blob: 9f0a8e3294d012815a0e1a2fd25bd87e7ffbbd9e (
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
52
53
54
55
|
class SessionsController < ApplicationController
# 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][:username_or_email]) || User.find_by_user_name(params[:session][:username_or_email])
#@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
@token = Session.hash_token(cookies[:remember_token])
@session = Session.find_by(token: @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_user_name, :session_password)
end
def is_owner?(object)
object.user == current_user
end
end
|