Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserSessionsController < ApplicationController
- def new
- @user = User.new
- end
- def create
- if @user = login(params[:email], params[:password])
- redirect_back_or_to(root_path, notice: 'Login successful')
- else
- flash.now[:alert] = 'Login failed'
- render action: 'new'
- end
- end
- def destroy
- logout
- redirect_to(root_path, notice: 'Logged out!')
- end
- def user_params
- params.require(:email).permit(:password)
- end
- end
- class PasswordResetsController < ApplicationController
- skip_before_filter :require_login
- def create
- @user = User.find_by_email(params[:email])
- @user.deliver_reset_password_instructions! if @user
- redirect_to(root_path, :notice => 'Instructions have been sent to your email.')
- end
- def edit
- @token = params[:id]
- @user = User.load_from_reset_password_token(params[:id])
- if @user.blank?
- not_authenticated
- return
- end
- end
- def update
- @token = params[:id]
- @user = User.load_from_reset_password_token(params[:id])
- if @user.blank?
- not_authenticated
- return
- end
- @user.password_confirmation = params[:user][:password_confirmation]=
- if @user.change_password!(params[:user][:password])
- redirect_to(root_path, :notice => 'Password was successfully updated.')
- else
- render :action => "edit"
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement