You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# app/controllers/users_controller.rbclassUsersControllerController < ApplicationControllerskip_before_action:verify_authenticity_token,only: [:create]defnewenddefcreate@user=User.build(user_create_params)if@user.save?set_session_token(@user.token)redirect_toroot_url(notice: 'Вы успешно зарегистировались')elserender:newendendprivatedefuser_create_paramsparams.require(:user).permit(:email)endend
Sign In controller
r g controller Sessions new
# app/controllers/sessions_controller.rbclassSessionsControllerController < ApplicationControllerskip_before_action:verify_authenticity_token,only: [:create]defnew@user=User.newenddefcreate@user=find_userif@user.present?set_session_token(@user.token)redirect_toroot_urlnotice: 'Вы успешно вошли на сайт'elserender:newendenddefdestroyset_session_token(nil)redirect_toroot_urlendprivatedefcreate_sessions_paramsparams.require(:user).permit(:email,:password)enddeffind_useruser=User.find_by(email: create_sessions_params[:email])returnnilifuser.nil?returnnilifuser.password != create_sessions_params[:password]userendend
The text was updated successfully, but these errors were encountered:
blackchestnut
changed the title
Simple authentication for Rails small apps without magic
Simple authentication for small Rails apps without magic
Nov 26, 2016
Simple authentication with password
Dependencies
Create user model
r g model User email crypted_password token
Add methods to the ApplicationController
Sign Up controller
r g controller Users new
Sign In controller
r g controller Sessions new
Routes
The text was updated successfully, but these errors were encountered: