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
|
# File 'app/controllers/devise_token_auth/sessions_controller.rb', line 10
def create
@user = User.find_by_email(resource_params[:email])
if @user and valid_params? and @user.valid_password?(resource_params[:password]) and @user.confirmed?
@client_id = SecureRandom.urlsafe_base64(nil, false)
@token = SecureRandom.urlsafe_base64(nil, false)
@user.tokens[@client_id] = {
token: BCrypt::Password.create(@token),
expiry: Time.now + 2.weeks
}
@user.save
render json: {
success: true,
data: @user.as_json
}
elsif @user and not @user.confirmed?
render json: {
success: false,
errors: [
"A confirmation email was sent to your account at #{@user.email}. "+
"You must follow the instructions in the email before your account "+
"can be activated"
]
}, status: 401
else
render json: {
success: false,
errors: ["Invalid login credentials. Please try again."]
}, status: 401
end
end
|