Class: SmsAuths::RequestsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/action_auth/sms_auths/requests_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/action_auth/sms_auths/requests_controller.rb', line 6

def create
  @user = User.find_or_initialize_by(phone_number: params[:phone_number])
  if @user.new_record?
    password = SecureRandom.hex(32)

    @user.email = "#{SecureRandom.hex(32)}@smsauth"
    @user.password = password
    @user.password_confirmation = password
    @user.verified = false

    @user.save!
  end

  code = rand(100_000..999_999)
  @user.update!(sms_code: code, sms_code_sent_at: Time.current)
  cookies.signed[:sms_auth_phone_number] = { value: @user.phone_number, httponly: true }

  if defined?(ActionAuth.configuration.sms_send_class) &&
    ActionAuth.configuration.sms_send_class.respond_to?(:send_code)
    ActionAuth.configuration.sms_send_class.send_code(@user.phone_number, code)
  end

  redirect_to sms_auths_sign_ins_path, notice: "Check your phone for a SMS Code."
end

#newObject



3
4
# File 'app/controllers/action_auth/sms_auths/requests_controller.rb', line 3

def new
end