Closed theblackzarc closed 1 year ago
Hi Jonathan. It's strange that kind of behavior. Have you modified the default code of MythAuth? I mean AuthController.php and view files. And please show me your config value of myth's $landingRoute variable, then $baseURL and $indexPage variables values.
And if you made modifications, please provide all of them.
Hai manageruz,
Editing AuthController.php is a no and for viewing i just rename it to login_old.php and register_old.php
i did this coz i just want to use my login and register template, but all the coding inside was same as the origin. see the picture i just send.
and here is my code inside my login template.
<?= $this->extend('auth/templates/layout'); ?>
<?= $this->section('content'); ?>
<title>LMS | SIGN IN</title>
<body class="hold-transition login-page">
<div class="login-box">
<div class="card card-outline card-primary">
<div class="card-header text-center">
<img src="assets/img/logo.png" alt="" style="width: 60%;">
</div>
<div class="card-body">
<p class="login-box-msg">Sign in to start your session</p>
<?= view('Myth\Auth\Views\_message_block') ?>
<form action="<?= route_to('login') ?>" method="post">
<?= csrf_field() ?>
<?php if ($config->validFields === ['email']) : ?>
<div class="input-group mb-3">
<input type="email" class="form-control <?php if (session('errors.login')) : ?>is-invalid<?php endif ?>" name="login" placeholder="<?= lang('Auth.email') ?>">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-envelope"></span>
</div>
</div>
<div class="invalid-feedback">
<?= session('errors.login') ?>
</div>
</div>
<?php else : ?>
<div class="input-group mb-3">
<input type="text" class="form-control <?php if (session('errors.login')) : ?>is-invalid<?php endif ?>" name="login" placeholder="<?= lang('Auth.emailOrUsername') ?>">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-envelope"></span>
</div>
</div>
<div class="invalid-feedback">
<?= session('errors.login') ?>
</div>
</div>
<?php endif; ?>
<div class="input-group mb-3">
<input type="password" name="password" class="form-control <?php if (session('errors.password')) : ?>is-invalid<?php endif ?>" placeholder="<?= lang('Auth.password') ?>">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
<div class="invalid-feedback">
<?= session('errors.password') ?>
</div>
</div>
<div class="row">
<div class="col-8">
<?php if ($config->allowRemembering) : ?>
<div class="icheck-primary">
<input type="checkbox" name="remember" class="form-check-input" <?php if (old('remember')) : ?> checked <?php endif ?>>
<label for="form-check-label">
<?= lang('Auth.rememberMe'); ?>
</label>
</div>
<?php endif; ?>
</div>
<div class="col-4">
<button type="submit" class="btn btn-primary btn-block"><?= lang('Auth.loginAction') ?></button>
</div>
</div>
</form>
<?php if ($config->activeResetter) : ?>
<p class="mb-1">
<a href="<?= route_to('forgot') ?>"><?= lang('Auth.forgotYourPassword'); ?></a>
</p>
<?php endif; ?>
</div>
</div>
</div>
<!-- jQuery -->
<script src="<?= base_url(); ?>assets/plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="<?= base_url(); ?>assets/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="<?= base_url(); ?>assets/dist/js/adminlte.min.js"></script>
</body>
<?= $this->endSection(); ?>
please let me know if i did something i'm not supposed.
Thank You manageruz.
Regards, Jonathan
You forget to show your config value of myth's $landingRoute variable, then $baseURL and $indexPage variables values.
owh sorry, i forgot..
here is the code
public $landingRoute = '/';
public $reservedRoutes = [
'login' => 'login',
'logout' => 'logout',
'register' => 'register',
'activate-account' => 'activate-account',
'resend-activate-account' => 'resend-activate-account',
'forgot' => 'forgot',
'reset-password' => 'reset-password',
];
public string $baseURL = 'http://sub.domain.com/';
public string $indexPage = '';
here it is manageruz. sorry i'm really forget about this. Thank You.
Regards, Jonathan
Hey Jonathan. I can't reproduce your error. It should be some kind of web server settings error. What's your webserver?
public string $baseURL = 'http://sub.domain.com/';
is this is your real url?
Hey Jonathan. I can't reproduce your error. It should be some kind of web server settings error. What's your webserver?
Hi manageruz, I'm using XAMPP and also Live Server with CPanel in it. both of them make the same problem but it is okay since we use it as internal web app.
public string $baseURL = 'http://sub.domain.com/';
is this is your real url?
nope.. it just some example.. but it is true I'm using it in sub domain not the domain primary.
Thank You manageruz for responding, it just annoying that I must click back at the browser then everything went normal.
if You want this to close so be it, since its not very important issue like others.
Thank You so much for Your time manageruz 🙏🏻
regards, Jonathan
It's interesting for me too. But as i said before i can't reproduce your error. Try to check your .htaccess file settings. It would be nice if you show it. It also might be a subdomain issue.
And which is your success registration notification ?
In the AuthController.php file before the code below (it's inside attemptLogin() method) dump the session('redirect_url') and site_url($this->config->landingRoute) variables and show me it's values please after successful registration message without refreshing the page:
$redirectURL = session('redirect_url') ?? site_url($this->config->landingRoute);
unset($_SESSION['redirect_url']);
Sorry manageruz for very late respond, had to travel outside.
It's interesting for me too. But as i said before i can't reproduce your error. Try to check your .htaccess file settings. It would be nice if you show it. It also might be a subdomain issue.
here is my .htaccess (default/never change)
# Disable directory browsing
Options -Indexes
# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
# RewriteBase /
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]
# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
# Disable server signature start
ServerSignature Off
# Disable server signature end
And which is your success registration notification ?
- Please confirm your account by clicking the activation link in the email we have sent.
- Welcome aboard! Please login with your new credentials.
No. 2
In the AuthController.php file before the code below (it's inside attemptLogin() method) dump the session('redirect_url') and site_url($this->config->landingRoute) variables and show me it's values please after successful registration message without refreshing the page:
$redirectURL = session('redirect_url') ?? site_url($this->config->landingRoute); unset($_SESSION['redirect_url']);
public function attemptLogin()
{
$rules = [
'login' => 'required',
'password' => 'required',
];
if ($this->config->validFields === ['email']) {
$rules['login'] .= '|valid_email';
}
if (!$this->validate($rules)) {
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}
$login = $this->request->getPost('login');
$password = $this->request->getPost('password');
$remember = (bool) $this->request->getPost('remember');
// Determine credential type
$type = filter_var($login, FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
// Try to log them in...
if (!$this->auth->attempt([$type => $login, 'password' => $password], $remember)) {
return redirect()->back()->withInput()->with('error', $this->auth->error() ?? lang('Auth.badAttempt'));
}
// Is the user being forced to reset their password?
if ($this->auth->user()->force_pass_reset === true) {
return redirect()->to(route_to('reset-password') . '?token=' . $this->auth->user()->reset_hash)->withCookies();
}
$redirectURL = session('redirect_url') ?? site_url('/'); <--- this part is not the same as You mention manageruz
$redirectURL = session('redirect_url') ?? site_url($this->config->landingRoute); <--- this is from You
unset($_SESSION['redirect_url']); <--- uncomment
return redirect()->to($redirectURL)->withCookies()->with('message', lang('Auth.loginSuccess'));
}
so I will comment it for now and try the result.. and here is the result (attached)
before changing attemptLogin()
$redirectURL = session('redirect_url') ?? site_url('/');
unset($_SESSION['redirect_url']);
return redirect()->to($redirectURL)->withCookies()->with('message', lang('Auth.loginSuccess'));
after first changing attemptLogin()
// $redirectURL = session('redirect_url') ?? site_url('/');
unset($_SESSION['redirect_url']);
// return redirect()->to($redirectURL)->withCookies()->with('message', lang('Auth.loginSuccess'));
after second changing attemptLogin()
$redirectURL = '';
unset($_SESSION['redirect_url']);
return redirect()->to($redirectURL)->withCookies()->with('message', lang('Auth.loginSuccess'));
and it works, many thanks manageruz for staying with me all times and days.
Thank You so much manageruz
Sorry for the edit.. just to make it clear though 😄
Hai guys,
I would need some help for this issue i'm facing with. oh also i've search the issue open or closed but nothing the same as my issue.
here is my step that will show the error:
How is it possible? and how to fix it? i've check the attemptRegister() and i think it will not route to http://localhost:8080/dist/js/adminlte.min.js
but if you've done with registration and then refresh the login page (the notification will be gone) it will not redirect to http://localhost:8080/dist/js/adminlte.min.js but go to home or http://localhost:8080
Codeiginter 4 version 4.3.6 Myth/Auth version 1.2.1 PHP Version 7.4.33
Many thanks, Jonathan