Sha256: 25d63f3c738e552d46e43d258b69582880722db63d13f082920ce0c6fed99fdc
Contents?: true
Size: 1.25 KB
Versions: 59
Compression:
Stored size: 1.25 KB
Contents
require_dependency "educode_sales/application_controller" module EducodeSales class SessionsController < ApplicationController layout "educode_sales/login" skip_before_action :authenticate_request def login end def create user = User.where("login = :acount OR mail = :acount OR phone = :acount", acount: params[:account]).first if user&.admin check_pwd(user) elsif user staff = Staff.find_by(user_id: user.id) if staff return render_failure('该账号已禁止使用') if staff.expired_at < Time.now check_pwd(user, staff) else render_failure('账号不存在') end else render_failure('账号或密码错误') end end def logout session[:admin_id] = nil redirect_to login_path end private def check_pwd(user, staff=nil) if user.check_password?(params[:password]) if staff.nil? staff = Staff.find_or_initialize_by(user_id: user.id) staff.is_admin = true staff.save unless staff.persisted? end session[:admin_id] = staff.id return render_success else return render_failure('账号或密码错误') end end end end
Version data entries
59 entries across 59 versions & 1 rubygems