Sha256: fbf8bf5fb3f0ed914ecb5889e7b0b6f0b845cd6eb896395bd8b144224c1cc89a

Contents?: true

Size: 1.3 KB

Versions: 5

Compression:

Stored size: 1.3 KB

Contents

class ExpressTranslate::AccountController < ExpressTranslate::BaseController
  # Check login status for goto page
  before_filter :check_login
  
  include ExpressTranslate
  
  # Login page html code only
  def login
    render layout: 'express_translate/login'
  end
  
  # 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
  def login_check
    account = Account.find(params[:username])
    if account.present? and account["password"] == Account.encoding(params[:password])
      account["token"] = new_token
      Account.update(account)
      render :json => {success: true, token: account["token"], username: account["username"]}
    else
      render :json => {success: false, error: "Username or password is incorrect!"}
    end
  end
  
  # Create token for login action, random string
  def new_token
    o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
    string = (0...50).map { o[rand(o.length)] }.join
  end
  
  # Check login status function
  # If logined auto change location for Client
  def check_login
    if check_authentication
      redirect_to controller: "options", action: "index"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
express_translate-1.0.5 app/controllers/express_translate/account_controller.rb
express_translate-1.0.4 app/controllers/express_translate/account_controller.rb
express_translate-1.0.3 app/controllers/express_translate/account_controller.rb
express_translate-1.0.2 app/controllers/express_translate/account_controller.rb
express_translate-1.0.1 app/controllers/express_translate/account_controller.rb