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
|
# File 'app/controllers/goldencobra/api/v1/tokens_controller.rb', line 8
def create
email = params[:email]
password = params[:password]
if email.nil? || password.nil?
render status: 400, json: { error: 'The request must contain ' +
'the user email and password.' }
return
end
@visitor = Visitor.find_by_email(email)
if @visitor == nil
render status: 401, json: { error: "Invalid email or password." }
return
end
@visitor.ensure_authentication_token!
if @visitor.valid_password?(password)
render status: 200, json: { token: @visitor.authentication_token }
else
render status: 401, json: { error: "Invalid email or password." }
end
end
|