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 |
# File 'lib/generators/authkit/templates/app/controllers/sessions_controller.rb', line 6 def create 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
25 26 27 28 29 30 31 |
# File 'lib/generators/authkit/templates/app/controllers/sessions_controller.rb', line 25 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 |