Sha256: f5d67016890f915954ba6993ab4ac2a91e2a784ce20e920468d89d9f18c2a049
Contents?: true
Size: 1.39 KB
Versions: 15
Compression:
Stored size: 1.39 KB
Contents
require_dependency "educode_sales/application_controller" module EducodeSales class SessionsController < ApplicationController layout "educode_sales/login" #todo 注意 修改模板(感觉是 整个控制器的html下都先导入该模板在导入对应的html) # 行 动 前 跳 过 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
15 entries across 15 versions & 1 rubygems