educoder/app/controllers/managements_controller.rb

107 lines
3.6 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class ManagementsController < ApplicationController
before_filter :require_admin
layout 'base_management'
include ManagementsHelper
include SortHelper
include UsersHelper
def users
@menu_type = 6
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)
end
def trial_authorization
@menu_type = 9
search = params[:search]
@status = trial_authorization_status(params[:status])
# @status = (params[:status].blank? || params[:status] == "0") ? 0 : [1,2]
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
# params[:type] 1拒绝 0同意
# authentication 会有一个初始值,不同的值代表不同的权限
# REDO: 后面权限改了后,一并要改
def trial_authorization_operation
apply_action = ApplyAction.find(params[:apply_id])
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
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
# copy from admin
def identity_authentication
@menu_type = 9
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
# 拒绝身份认证
# 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
end