educoder/app/controllers/managements_controller.rb

107 lines
3.6 KiB
Ruby
Raw Normal View History

2017-06-07 17:39:24 +08:00
class ManagementsController < ApplicationController
before_filter :require_admin
layout 'base_management'
include ManagementsHelper
2017-06-08 16:15:24 +08:00
include SortHelper
include UsersHelper
2017-06-07 17:39:24 +08:00
2017-06-08 11:17:29 +08:00
def users
@menu_type = 6
2017-06-08 16:15:24 +08:00
sort_init 'login', 'asc'
sort_update %w(login firstname lastname mail admin created_on last_login_on)
case params[:format]
when 'xml', 'json'
@offset, @limit = api_offset_and_limit({:limit => 50})
else
@limit = 50 #per_page_option
end
@status = params[:status] || 1
scope = User.logged.status(@status)
scope = User.like(params[:name]) if params[:name].present?
scope = scope.in_group(params[:group_id]) if params[:group_id].present?
@user_count = scope.count
@user_pages = Paginator.new @user_count, @limit, params['page']
@offset ||= @user_pages.offset
@users = scope.order(sort_clause).limit(@limit).offset(@offset).all
respond_to do |format|
format.html {
@groups = Group.all.sort
}
format.api
end
end
def users_trial
@menu_type = 6
@authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => 0).includes(:user)
2017-06-08 11:17:29 +08:00
end
2017-06-07 17:39:24 +08:00
def trial_authorization
2017-06-08 11:17:29 +08:00
@menu_type = 9
2017-06-07 17:39:24 +08:00
search = params[:search]
@status = trial_authorization_status(params[:status])
2017-06-08 10:53:11 +08:00
# @status = (params[:status].blank? || params[:status] == "0") ? 0 : [1,2]
2017-06-07 17:39:24 +08:00
if search.blank?
@authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status).includes(:user)
else
user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{search}%'")
@authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status, :user_id => user_id).includes(:user)
end
end
2017-06-08 17:45:39 +08:00
# params[:type] 1拒绝 0同意
# authentication 会有一个初始值,不同的值代表不同的权限
# REDO: 后面权限改了后,一并要改
2017-06-07 17:39:24 +08:00
def trial_authorization_operation
apply_action = ApplyAction.find(params[:apply_id])
2017-06-08 17:45:39 +08:00
if params[:type] == "0"
authentication_user = AuthenticationsUsers.where(:user_id => apply_action.user_id).first
if authentication_user.blank?
AuthenticationsUsers.create(:user_id => apply_action.user_id, :authentication_id => 1)
end
end
2017-06-07 17:39:24 +08:00
apply_action.update_attributes(:status => (params[:type] == "1" ? 2 : 1), :reason => params[:reject_reason], :dealer_id => User.current.id)
redirect_to '/managements/trial_authorization.js'
end
def index
end
2017-06-08 10:53:11 +08:00
# copy from admin
2017-06-07 17:39:24 +08:00
def identity_authentication
2017-06-08 11:17:29 +08:00
@menu_type = 9
2017-06-07 17:39:24 +08:00
type = params[:type] || 0 # 存在type 就用type 没有就为 0
user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:name]}%'")
@unapproved_user = ApplyUserAuthentication.where(:status => type, :user_id => user_id).order("updated_at desc")
respond_to do |format|
format.html
format.js
end
end
2017-06-08 10:53:11 +08:00
# 拒绝身份认证
# copy from admin
def reject_authentication
apply_user = ApplyUserAuthentication.find(params[:apply_id])
reason = apply_user.update_attributes(:status => 2, :remarks => params[:reject_reason])
render :json => {success: reason}
end
# 统一身份认证
# copy from admin
def agree_authentication
apply_user = ApplyUserAuthentication.find(params[:apply_id])
user = User.find(apply_user.user_id)
apply_user.update_attribute(:status, 1)
user.update_attribute(:authentication, true)
@unapproved_user = ApplyUserAuthentication.where(:status => 0).order("updated_at desc")
respond_to do |format|
format.js
end
end
2017-06-07 17:39:24 +08:00
end