Class: ExpressTranslate::AccountController

Inherits:
BaseController
  • Object
show all
Includes:
ExpressTranslate
Defined in:
app/controllers/express_translate/account_controller.rb

Instance Method Summary collapse

Methods included from ExpressTranslate

clear, config, #language, reset, root, seeds, setup

Methods inherited from BaseController

#check_authentication

Instance Method Details

#check_loginObject

Check login status function If logined auto change location for Client



43
44
45
46
47
# File 'app/controllers/express_translate/account_controller.rb', line 43

def 
  if check_authentication
    redirect_to controller: "options", action: "index"
  end
end

#loginObject

Login page html code only



8
9
10
# File 'app/controllers/express_translate/account_controller.rb', line 8

def 
  render layout: 'express_translate/login'
end

#login_checkObject

Login action Find account with username Change exists of account and change password for account (encoding password) If oke, new token for account login and update token for account Render json data for client Successful or Error



17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/express_translate/account_controller.rb', line 17

def 
   = Account.find(params[:username])
  if .present? and ["password"] == Account.encoding(params[:password])
    token = new_token
    ["token"] = [["token"], token].join
    Account.update()
    render :json => {success: true, token: token, username: ["username"]}
  else
    render :json => {success: false, error: "Username or password is incorrect!"}
  end
end

#new_tokenObject

Create token for login action, random string



30
31
32
33
# File 'app/controllers/express_translate/account_controller.rb', line 30

def new_token
  o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
  string = (0...50).map { o[rand(o.length)] }.join
end

#resetObject

Reset account with url



36
37
38
39
# File 'app/controllers/express_translate/account_controller.rb', line 36

def reset
  Account.reset
  redirect_to action: "login"
end