Class: Mobile::UsersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/mobile/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#sign_inObject



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 
  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