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
|
# File 'app/controllers/mobile/users_controller.rb', line 4
def sign_in
user = User.find_by_email(params[:email])
if user && user.valid_password?(params[:password])
if user.organizations.empty?
error = {
:error => "Could not sign in",
:reason => "User is not a member of any organizations",
:code => 2
}
render :json => error, :status => 422 and return
end
now = Time.parse(params[:now]) rescue Time.zone.now
render :json => user, :auth_token => true, :organization => user.organizations.first, :now => now
else
error = {
:error => "Could not sign in",
:reason => "Invalid email/password",
:code => 1
}
render :json => error, :status => 422
end
end
|