2013-08-23 14:20:43 +08:00
|
|
|
class Auth::Result
|
|
|
|
attr_accessor :user, :name, :username, :email, :user,
|
|
|
|
:email_valid, :extra_data, :awaiting_activation,
|
2013-08-28 15:18:31 +08:00
|
|
|
:awaiting_approval, :authenticated, :authenticator_name,
|
2015-03-03 01:13:10 +08:00
|
|
|
:requires_invite, :not_allowed_from_ip_address,
|
|
|
|
:admin_not_allowed_from_ip_address
|
2013-08-23 14:20:43 +08:00
|
|
|
|
|
|
|
def session_data
|
|
|
|
{
|
|
|
|
email: email,
|
|
|
|
username: username,
|
|
|
|
email_valid: email_valid,
|
|
|
|
name: name,
|
|
|
|
authenticator_name: authenticator_name,
|
|
|
|
extra_data: extra_data
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_client_hash
|
2013-08-28 15:18:31 +08:00
|
|
|
if requires_invite
|
|
|
|
{ requires_invite: true }
|
|
|
|
elsif user
|
2015-01-20 01:36:56 +08:00
|
|
|
if user.suspended?
|
|
|
|
{
|
|
|
|
suspended: true,
|
|
|
|
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} )
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
authenticated: !!authenticated,
|
|
|
|
awaiting_activation: !!awaiting_activation,
|
|
|
|
awaiting_approval: !!awaiting_approval,
|
2015-03-03 01:13:10 +08: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-20 01:36:56 +08:00
|
|
|
}
|
|
|
|
end
|
2013-08-23 14:20:43 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
email: email,
|
|
|
|
name: User.suggest_name(name || username || email),
|
|
|
|
username: UserNameSuggester.suggest(username || name || email),
|
|
|
|
# this feels a tad wrong
|
|
|
|
auth_provider: authenticator_name.capitalize,
|
|
|
|
email_valid: !!email_valid
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|