Class: Auth::AdminCreateUsersController

Inherits:
ApplicationController show all
Includes:
Concerns::DeviseConcern, Concerns::TokenConcern
Defined in:
app/controllers/auth/admin_create_users_controller.rb

Constant Summary collapse

CONDITIONS_FOR_TOKEN_AUTH =

only these actions need an authenticated user to be present for them to be executed.

[:create,:update,:destroy,:edit,:new,:index,:show]
TCONDITIONS =
{:only => CONDITIONS_FOR_TOKEN_AUTH}

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_resource!, #build_model_from_params, #check_for_create, #check_for_destroy, #check_for_update, #from_bson, #from_view, #get_model_class_name, #instantiate_classes, #not_found

Instance Method Details

#createObject

User.where(:email => “[email protected]”).first.delete POST /auth/admin_create_users



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/auth/admin_create_users_controller.rb', line 48

def create
  k = SecureRandom.hex(24)
  @auth_user.password = k
  @auth_user.password_confirmation = k
  @auth_user.m_client = self.m_client
  @auth_user.created_by_admin = true
  respond_to do |format|
    if @auth_user.save
      if !@auth_user..blank?
        format.html {render "auth/confirmations/enter_otp.html.erb"}
        format.json {render json: @auth_user.to_json, status: :created}
      else
        format.html {render "auth/admin_create_users/show.html.erb"}
        format.json {render json: @auth_user.to_json, status: :created}
      end
    else
      format.html {render "new.html.erb"}
      format.json {render json:  {:errors => @auth_user.errors}, status: 422}
    end
  end
end

#destroyObject

DELETE /auth/admin_create_users/1



78
79
80
81
# File 'app/controllers/auth/admin_create_users_controller.rb', line 78

def destroy
  @auth_admin_create_user.destroy
  redirect_to auth_admin_create_users_url, notice: 'Admin create user was successfully destroyed.'
end

#editObject

GET /auth/admin_create_users/1/edit



43
44
# File 'app/controllers/auth/admin_create_users_controller.rb', line 43

def edit
end

#indexObject

GET /auth/admin_create_users



26
27
28
# File 'app/controllers/auth/admin_create_users_controller.rb', line 26

def index
  #@auth_admin_create_users = Auth::AdminCreateUser.all
end

#initialize_varsObject

called before all the actions.



15
16
17
18
19
20
21
22
23
# File 'app/controllers/auth/admin_create_users_controller.rb', line 15

def initialize_vars
  
  @auth_user_class = Auth.configuration.user_class.constantize

  @auth_user_params = permitted_params.fetch(:user,{}) 

  @auth_user = params[:id] ? @auth_user_class.find(params[:id]) : @auth_user_class.new(@auth_user_params)
  
end

#newObject

GET /auth/admin_create_users/new



35
36
37
38
39
40
# File 'app/controllers/auth/admin_create_users_controller.rb', line 35

def new
  # what kind of form should be presented to the admin.

  #@auth_admin_create_user = Auth::AdminCreateUser.new
  ## just render a form with the user model.
end

#permitted_paramsObject



83
84
85
# File 'app/controllers/auth/admin_create_users_controller.rb', line 83

def permitted_params
  params.permit({user: ([:email,:additional_login_param, :password, :password_confirmation] + Devise::ParameterSanitizer::DEFAULT_PERMITTED_ATTRIBUTES[:account_update]).uniq},:id)    
end

#showObject

GET /auth/admin_create_users/1



31
32
# File 'app/controllers/auth/admin_create_users_controller.rb', line 31

def show
end

#updateObject

PATCH/PUT /auth/admin_create_users/1



71
72
73
74
75
# File 'app/controllers/auth/admin_create_users_controller.rb', line 71

def update
  ## should also allow stuff like
  ## resend sms otp
  ## resend confirmation email
end