Class: User::Operation::ExternalSignIn

Inherits:
Trailblazer::Operation
  • Object
show all
Defined in:
app/concepts/morpho/user/operation/external_sign_in.rb

Instance Method Summary collapse

Instance Method Details

#authentication_token(options) ⇒ Object



78
79
80
# File 'app/concepts/morpho/user/operation/external_sign_in.rb', line 78

def authentication_token (options, **)
  options['token'] = Morpho::JWT::Payload.new(options['user.model'])
end

#find_authentication(options) ⇒ Object



19
20
21
22
23
24
# File 'app/concepts/morpho/user/operation/external_sign_in.rb', line 19

def find_authentication (options, **)
  options['authentication.model'] = Morpho::Authentication.find_by(
    uid: options['data']['uid'],
    provider: options['data']['provider']
  )
end

#find_user(options) ⇒ Object



26
27
28
# File 'app/concepts/morpho/user/operation/external_sign_in.rb', line 26

def find_user (options, **)
  options['user.model'] = Morpho::User.find_by(email: options['data']['email'])
end

#generate_refresh_token(options) ⇒ Object



54
55
56
# File 'app/concepts/morpho/user/operation/external_sign_in.rb', line 54

def generate_refresh_token (options, **)
  options['user.model'].generate_refresh_token!
end

#not_registered(options) ⇒ Object



70
71
72
# File 'app/concepts/morpho/user/operation/external_sign_in.rb', line 70

def not_registered (options, **)
  options['error'] = :not_registered
end

#not_signed_in(options) ⇒ Object



66
67
68
# File 'app/concepts/morpho/user/operation/external_sign_in.rb', line 66

def not_signed_in (options, **)
  options['error'] = :not_signed_in
end

#not_signed_up(options) ⇒ Object



74
75
76
# File 'app/concepts/morpho/user/operation/external_sign_in.rb', line 74

def not_signed_up (options, **)
  options['error'] = :not_signed_up
end

#not_valid(options) ⇒ Object



62
63
64
# File 'app/concepts/morpho/user/operation/external_sign_in.rb', line 62

def not_valid (options, **)
  options['error'] = :not_valid
end

#register(options) ⇒ Object



36
37
38
39
40
41
42
# File 'app/concepts/morpho/user/operation/external_sign_in.rb', line 36

def register (options, **)
  if options['user.model'] && !options['authentication.model']
    provider = options['data']['provider'].downcase

    options['user.model'].add_provider_to_user(provider, options['data']['uid'])
  end
end

#register_last_login_activity(options) ⇒ Object



58
59
60
# File 'app/concepts/morpho/user/operation/external_sign_in.rb', line 58

def  (options, **)
  options['user.model'].(options['ip'])
end

#sign_in(options) ⇒ Object



30
31
32
33
34
# File 'app/concepts/morpho/user/operation/external_sign_in.rb', line 30

def  (options, **)
  if options['authentication.model']
    options['user.model'] = options['authentication.model'].user
  end
end

#sign_up(options) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'app/concepts/morpho/user/operation/external_sign_in.rb', line 44

def  (options, **)
  if !options['user.model'] && !options['authentication.model']
    provider = options['data']['provider'].downcase

    options['user.model'] = Morpho::User.create_from_provider(provider, options['data']['uid'], {
      email: options['data']['email']
    })
  end
end

#validate(options) ⇒ Object



14
15
16
17
# File 'app/concepts/morpho/user/operation/external_sign_in.rb', line 14

def validate (options, **)
  options['contract'] = Morpho::User::Contract::ExternalSignIn.new(OpenStruct.new)
  options['contract'].validate(options['data'])
end