2013-08-23 02:20:43 -04:00
|
|
|
class Auth::Result
|
|
|
|
attr_accessor :user, :name, :username, :email, :user,
|
|
|
|
:email_valid, :extra_data, :awaiting_activation,
|
2013-08-28 03:18:31 -04:00
|
|
|
:awaiting_approval, :authenticated, :authenticator_name,
|
2015-03-02 12:13:10 -05:00
|
|
|
:requires_invite, :not_allowed_from_ip_address,
|
2016-09-07 14:05:46 -04:00
|
|
|
:admin_not_allowed_from_ip_address, :omit_username,
|
|
|
|
:skip_email_validation
|
2013-08-23 02:20:43 -04:00
|
|
|
|
2017-11-09 10:49:12 -05:00
|
|
|
attr_accessor(
|
|
|
|
:failed,
|
|
|
|
:failed_reason,
|
|
|
|
:failed_code
|
|
|
|
)
|
2015-06-24 12:12:43 -04:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
@failed = false
|
|
|
|
end
|
|
|
|
|
|
|
|
def failed?
|
|
|
|
!!@failed
|
|
|
|
end
|
|
|
|
|
2013-08-23 02:20:43 -04:00
|
|
|
def session_data
|
2015-06-24 12:12:43 -04:00
|
|
|
{ email: email,
|
2013-08-23 02:20:43 -04:00
|
|
|
username: username,
|
|
|
|
email_valid: email_valid,
|
2015-06-26 15:52:05 -04:00
|
|
|
omit_username: omit_username,
|
2013-08-23 02:20:43 -04:00
|
|
|
name: name,
|
|
|
|
authenticator_name: authenticator_name,
|
2016-09-07 14:05:46 -04:00
|
|
|
extra_data: extra_data,
|
|
|
|
skip_email_validation: !!skip_email_validation }
|
2013-08-23 02:20:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_client_hash
|
2013-08-28 03:18:31 -04:00
|
|
|
if requires_invite
|
|
|
|
{ requires_invite: true }
|
|
|
|
elsif user
|
2015-01-19 12:36:56 -05:00
|
|
|
if user.suspended?
|
|
|
|
{
|
|
|
|
suspended: true,
|
2017-07-27 21:20:09 -04:00
|
|
|
suspended_message: I18n.t(user.suspend_reason ? "login.suspended_with_reason" : "login.suspended",
|
|
|
|
date: I18n.l(user.suspended_till, format: :date_only), reason: user.suspend_reason)
|
2015-01-19 12:36:56 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
authenticated: !!authenticated,
|
|
|
|
awaiting_activation: !!awaiting_activation,
|
|
|
|
awaiting_approval: !!awaiting_approval,
|
2015-03-02 12:13:10 -05:00
|
|
|
not_allowed_from_ip_address: !!not_allowed_from_ip_address,
|
|
|
|
admin_not_allowed_from_ip_address: !!admin_not_allowed_from_ip_address
|
2015-01-19 12:36:56 -05:00
|
|
|
}
|
|
|
|
end
|
2013-08-23 02:20:43 -04:00
|
|
|
else
|
2015-10-29 12:19:09 -04:00
|
|
|
result = { email: email,
|
|
|
|
username: UserNameSuggester.suggest(username || name || email),
|
|
|
|
# this feels a tad wrong
|
|
|
|
auth_provider: authenticator_name.capitalize,
|
|
|
|
email_valid: !!email_valid,
|
|
|
|
omit_username: !!omit_username }
|
|
|
|
|
|
|
|
if SiteSetting.enable_names?
|
|
|
|
result[:name] = User.suggest_name(name || username || email)
|
|
|
|
end
|
|
|
|
|
|
|
|
result
|
2013-08-23 02:20:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|