Skip to content

Commit

Permalink
Add language field in reset pass and confirm acc events (openware#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
ec authored and Louis committed Feb 15, 2019
1 parent 0155d3d commit 0a846a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
18 changes: 13 additions & 5 deletions app/api/v2/identity/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def parse_refid!
requires :email, type: String, desc: 'User Email', allow_blank: false
requires :password, type: String, desc: 'User Password', allow_blank: false
optional :refid, type: String, desc: 'Referral uid'
optional :lang, type: String, desc: 'Client env language'
optional :captcha_response, types: [String, Hash],
desc: 'Response from captcha widget'
end
Expand All @@ -43,7 +44,7 @@ def parse_refid!
# FIXME: active record validation
error!(user.errors.full_messages, 422) unless user.save

publish_confirmation(user)
publish_confirmation(user, params[:lang])
status 201
end

Expand All @@ -63,14 +64,16 @@ def parse_refid!
requires :email, type: String,
desc: 'Account email',
allow_blank: false
optional :lang, type: String,
desc: 'Client env language'
end
post '/generate_code' do
current_user = User.find_by_email(params[:email])
if current_user.nil? || current_user.active?
error!({ errors: ['identity.user.active_or_doesnt_exist'] }, 422)
end

publish_confirmation(current_user)
publish_confirmation(current_user, params[:lang_code])
status 201
end

Expand Down Expand Up @@ -115,8 +118,10 @@ def parse_refid!
]
params do
requires :email, type: String,
desc: 'Account email',
allow_blank: false
desc: 'Account email',
allow_blank: false
optional :lang, type: String,
desc: 'Client env language'
end

post '/generate_code' do
Expand All @@ -128,7 +133,10 @@ def parse_refid!

activity_record(user: current_user.id, action: 'request password reset', result: 'succeed', topic: 'password')

EventAPI.notify('system.user.password.reset.token', user: current_user.as_json_for_event_api, token: token)
EventAPI.notify('system.user.password.reset.token',
user: current_user.as_json_for_event_api,
language: params[:lang] ||= 'en',
token: token)
status 201
end

Expand Down
3 changes: 2 additions & 1 deletion app/api/v2/identity/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ def token_uniq?(jti)
Rails.cache.write(jti, 'utilized')
end

def publish_confirmation(user)
def publish_confirmation(user, language)
token = codec.encode(sub: 'confirmation', email: user.email, uid: user.uid)
EventAPI.notify(
'system.user.email.confirmation.token',
user: user.as_json_for_event_api,
language: language ||= 'en',
token: token
)
end
Expand Down

0 comments on commit 0a846a5

Please sign in to comment.