How to save previous URL on Password Reset Blade in Laravel - laravel

I have a blade with a password reset code (e.g. edit.blade)
I want to make that after a successful password change the user can return to the page from which he went to this blade (by pressing "Exit").
But the standard solution:
Exit
doesn't work because after successfully updating the password and displaying a message about it, the previous URL becomes URL that belongs to edit.blade.
How can I save the route from which the user entered the edit.blade??

Related

How to display a flash message along with redirect without using Session in laravel?

I have a part of code which checks for the file uploaded by user. If I find that is file is not a valid png/jpg/jpeg file then I am deactivating the user and logging him out from the site and deleting his session and then redirecting him to login page. I want to display the error to him that he/she is trying to upload an invalid file. I am not able to find anything on how to display it without using Session.
Any help will be appreciated.
You can create new session messages after flush the session, these messages will delete after shown
controller
$is_valid // boolean
if(!is_valid) {
// if file is not valid, do something
...
// clear all session
session()->flush()
// redirect user to login page and send session message
return redirect()->route("login")
->with("message","Your file is not valid")
->with("message_type","danger");
login.blade
#if(session()->has("message"))
<div class="alert alert-{{session("message_type")}}">
<p> {{session("message")}} </p>
</div>
#endif
For example, if you don't want to use session for some reason, this is a simple code to show the error message in a specific view and then we give to the user a link to login again.
UploadController.php
public function myUpload(){
//... some stuff and then logout the user, delete the session
return view('uploadError', ['uploadError' => 'for some reason...']);
}
uploadError.blade.php
Error uploading the file: {{ $uploadError }}
Login again
In your case, you can't use the error sessions system because when you delete it, in this moment the user haven't a session, and the response has not session. And if you redirect to the login page from the controller, this login request will generate the new session, not before.

Redirecting from one View to another and changing the whole URL codeigniter

I am working on codeigniter and I am making a login page. When i validate the credentials I wan to move the user to next view if the credentials are correct.
I am using following command to redirect the user but it is merging the new view to the existing view and the url being shown in the browser is also getting appended.
$this->load->view('DataEntry');
URL before executing this command :http://127.0.0.1:8080/ci/
URL after executing this command : http://127.0.0.1:8080/ci/index.php/CI/DataEntry
how can i redirect the user from one view to another without appending the url and what is the right way to do it ?
I am an abolute beginner. so accept my apologies for dumb questions.
In general, it should be something like this:
//pseudo code
if ($validation_passed)
{
redirect('secret_page_controller/secretpage_method');
}
else
{
//if validation failed
$this->load->view('view_where_login_form_is');
}
Follow basic example from docs.
Please, format your code appropriate and add controller/method(s) code.

after uploading sample data into magento I can't log in

"Invalid User Name or Password." i try resetting the password but the email doesn't go through. I inserted the login details on the database & it still doesn't allow me to login. Please help.
try this query (in php myadmin)
UPDATE `admin_user` SET `password` = MD5('NEWPASSWORD') WHERE `username` = 'ADMINUSERNAME';
Try to delete everything inside var folder
\magento\var\
Try using the script for creating a new Admin user:
https://gist.github.com/litzinger/48be5876d6bba1509323
Next, you can restore your user from the Admin panel, and delete the one you don't need.
If the error is triggered by the issue with the frontend user, it's OK. The point is that Magento uses sample data to fill in the Users table. In this case, you should restore your database from the backup file.
open file app/code/core/Mage/Admin/Model/User.php
find function named
authenticate($username, $password)
and put
return true;
after following statement
$this->loadByUsername($username);
after that user your administartor user's username and anything in password, and try logging in. After successful Login change password from inside admin pannel.

Laravel - Redirect::intended route not working

I have a laravel built blog, and to comment on a post (if you're logged out) you must login. I put a link like this:
login to do this.
This redirects to the login form, which once filled out and user is authenticated, I have this:
return Redirect::intended('/');
Which takes the user to the homepage, not the page they intended to be on, in this case, the page with the post that they clicked the login link from to be able to comment. How can I return them back to the intended url in this case?
Actually, Redirect::intended('/') works if there is a key available in the session as url.intended otherwise it redirects to the default URL which is in your case '/', so definitely you didn't put the URL in the session. To accomplish this, you may put the URL in the session using something like this:
Session::put('url.intended', 'url...');
So, probably, in the login link, you may add a query string like this:
login
So, you can track the redirect and in that route's method (before return View) just put the previous URL in the session, using something like this:
if(Input::get('intended')) {
Session::put('url.intended', URL::previous());
}
Then before you redirect from there, you should remove the URL from the session using something like this:
$intendedUrl = Session::get('url.intended', url('/'));
Session::forget('url.intended');
return Redirect::to($intendedUrl);
This should solve the issue. Also, you may check this answer, could be helpful.
Redirect::intended requires two parts to work. The first is when the user tries to access a restricted page /orders but they aren't logged in you redirect them to the login page via:
redirect()->guest('/login');
Then on your login post-back if authentication is successful you call:
redirect()->intended('/dashboard');

Magento - Redirect back (similar to using setBeforeAuthUrl) when user creates a new account

I have the following controller action, which redirects to the login page if no user is logged in:
public function requireloginAction() {
if(!Mage::getSingleton('customer/session')->isLoggedIn()) {
// Not logged in
// Save requested URL for later redirection
Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());
header("Status: 301");
header('Location: '.Mage::helper('customer')->getLoginUrl()); // send to the login page
}
else {
// Logged in
.. do something ..
}
}
By using setBeforeAuthUrl, once the user logs in he/she is redirected back to this action.
Problem:
If instead of logging in, the user, creates an account he/she is then redirected to the main page, rather then to the url set in setBeforeAuthUrl.
Question:
Is there something similar to setBeforeAuthUrl that works with Account Creation too? Or how can I achieve the desired effect?
(Magento Version 1.6)
You can try using the following extension. http://www.magentocommerce.com/magento-connect/MagePsycho/extension/3763/custom_login_redirect
Or you can also open app/code/core/Mage/Customer/controllers/AccountController.php and look for the createPostAction() function around line 328 edit:
$url = $this->_welcomeCustomer($customer);
$this->_redirectSuccess($url);
to
$url = 'http://www.mycustomrediurecturl.com';
$this->_redirectSuccess($url);
If you want to do it the nice way override the controller add configuration options and make it a module :)
Cheers
Found solution.
First of all, setBeforeAuthUrl($url) does work for both "Log In" and "New Account Creation"!
The main difference (and the reason I had the problem) is that for a "New Account Creation" Magento checks if $url is within the domain name of the current store and if it is not, it redirects to the "My Account" page. While the redirection for "Log In" redirects to any $url.
I do not know if this is a bug or a feature (I'm using V1.6.0.0).
So just make sure to redirect to a url within the domain name of the current store - especially in a Multi Store configuration.

Resources