Class: ExpressTranslate::AccountController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- ExpressTranslate::AccountController
- Includes:
- ExpressTranslate
- Defined in:
- app/controllers/express_translate/account_controller.rb
Instance Method Summary collapse
-
#check_login ⇒ Object
Check login status function If logined auto change location for Client.
-
#login ⇒ Object
Login page html code only.
-
#login_check ⇒ Object
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.
-
#new_token ⇒ Object
Create token for login action, random string.
-
#reset ⇒ Object
Reset account with url.
Methods included from ExpressTranslate
clear, config, #language, reset, root, seeds, setup
Methods inherited from BaseController
Instance Method Details
#check_login ⇒ Object
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 check_login if check_authentication redirect_to controller: "options", action: "index" end end |
#login ⇒ Object
Login page html code only
8 9 10 |
# File 'app/controllers/express_translate/account_controller.rb', line 8 def login render layout: 'express_translate/login' end |
#login_check ⇒ Object
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 login_check account = Account.find(params[:username]) if account.present? and account["password"] == Account.encoding(params[:password]) token = new_token account["token"] = [account["token"], token].join Account.update(account) render :json => {success: true, token: token, username: account["username"]} else render :json => {success: false, error: "Username or password is incorrect!"} end end |
#new_token ⇒ Object
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 |