blob: b5ea29b087d84d954fd904c4cfa954f451978230 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
class SessionsController < ApplicationController
before_action :set_session, only: [:destroy]
# GET /sessions/new
def new
@user = User.new
#@session = Session.new
end
# POST /sessions
# POST /sessions.json
def create
# find the user...
@user = User.find_by(email: params[:session][:email].downcase)
#@session = Session.new(@user)
# ... and create a new session
respond_to do |format|
if @user && @user.authenticate(params[:session][:password])
sign_in @user
format.html { redirect_to root_path }
#format.json { #TODO }
else
format.html { render action: 'new' }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
# DELETE /sessions/1
# DELETE /sessions/1.json
def destroy
#@session.destroy
sign_out
respond_to do |format|
format.html { redirect_to root_path }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_session
#@session = Session.find(cookies[:remember_token])
end
# Never trust parameters from the scary internet, only allow the white list through.
def session_params
params.require(:session).permit(:session_email, :session_password)
end
end
|