app/controllers/dry_auth/api/v1/tokens_controller.rb
# 
# Taken from a POST request
# Generate a token and return it to the user
#
Taken from a POST request
Generate a token and return it to the user
Taken from a POST request Generate a token and return it to the user
def create
          login = params[:login]
          password = params[:password]
          if request.format != :json
            render status: 406, json: {message: "The request must be json"}
            return
          end
          if login.nil? or password.nil?
            render status: 400, json: {message: "The request must contain the user email and password."}
            return
          end
          @user = User.find_by_login(login)
          if @user.nil?
            Rails.logger.info "User #{login} failed signin, user cannot be found."
            render status: 401, json: {message: "Invalid username, email or passoword."}
            return
          end
          @user.ensure_authentication_token!
          if not @user.valid_password?(password)
            Rails.logger.info "User #{login} failed signin, password \"#{password}\" is invalid" 
            render status: 401, json: {message: "Invalid username, email or password."}
          else
            render status: 200, json: {token: @user.authentication_token}
          end
        end
def create login = params [ :login ] password = params [ :password ] if request . format != :json render status : 406 , json : { message : "The request must be json" } return end if login . nil? or password . nil? render status : 400 , json : { message : "The request must contain the user email and password." } return end @user = User . find_by_login ( login ) if @user . nil? Rails . logger . info "User #{login} failed signin, user cannot be found." render status : 401 , json : { message : "Invalid username, email or passoword." } return end @user . ensure_authentication_token! if not @user . valid_password? ( password ) Rails . logger . info "User #{login} failed signin, password \"#{password}\" is invalid" render status : 401 , json : { message : "Invalid username, email or password." } else render status : 200 , json : { token : @user . authentication_token } end end
Taken from a POST request
Generate a token and return it to the user
Taken from a POST request Generate a token and return it to the user
#Rails.logger.debug 'Receiving request' #Rails.logger.debug request #email = params[:email] # http://rdoc.info/github/plataformatec/devise/master/Devise/Models/TokenAuthenticatable