Class: SessionsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- SessionsController
- Defined in:
- lib/generators/authkit/templates/app/controllers/sessions_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
-
#destroy ⇒ Object
Logout.
-
#new ⇒ Object
Login.
Instance Method Details
#create ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/generators/authkit/templates/app/controllers/sessions_controller.rb', line 6 def create username_or_email = "#{params[:email]}".downcase user = User.find_by_username_or_email(username_or_email) if username_or_email.present? if user && user.authenticate(params[:password]) login(user) respond_to do |format| format.json { head :no_content } format.html { redirect_back_or_default } end else respond_to do |format| format.json { render json: { errors: ["Invalid user name or password"], status: "error" }, status: 422 } format.html { flash.now[:error] = "Invalid user name or password" render :new } end end end |
#destroy ⇒ Object
Logout
28 29 30 31 32 33 34 |
# File 'lib/generators/authkit/templates/app/controllers/sessions_controller.rb', line 28 def destroy logout respond_to do |format| format.json { head :no_content } format.html { redirect_to root_path } end end |
#new ⇒ Object
Login
3 4 |
# File 'lib/generators/authkit/templates/app/controllers/sessions_controller.rb', line 3 def new end |