mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
MID response handling
This commit is contained in:
parent
418bd2046c
commit
5f2e0619e5
3 changed files with 52 additions and 20 deletions
|
@ -22,12 +22,12 @@ class Registrar::SessionsController < SessionsController
|
||||||
phone = params[:user][:phone]
|
phone = params[:user][:phone]
|
||||||
client = Digidoc::Client.new
|
client = Digidoc::Client.new
|
||||||
|
|
||||||
country_codes = {'+372' => 'EST'}
|
# country_codes = {'+372' => 'EST'}
|
||||||
|
|
||||||
response = client.authenticate(
|
response = client.authenticate(
|
||||||
:phone => "+372#{phone}",
|
phone: "+372#{phone}",
|
||||||
:message_to_display => 'Authenticating',
|
message_to_display: 'Authenticating',
|
||||||
:service_name => 'Testing'
|
service_name: 'Testing'
|
||||||
)
|
)
|
||||||
|
|
||||||
@user = find_user_by_idc(response.user_id_code)
|
@user = find_user_by_idc(response.user_id_code)
|
||||||
|
@ -37,12 +37,8 @@ class Registrar::SessionsController < SessionsController
|
||||||
session[:mid_session_code] = client.session_code
|
session[:mid_session_code] = client.session_code
|
||||||
render json: { message: t('check_your_phone_for_confirmation_code') }, status: :ok
|
render json: { message: t('check_your_phone_for_confirmation_code') }, status: :ok
|
||||||
else
|
else
|
||||||
flash[:alert] = t('no_such_user')
|
render json: { message: t('no_such_user') }, status: :unauthorized
|
||||||
flash.keep(:alert)
|
|
||||||
render js: "window.location = '#{registrar_login_mid_path}'"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# client.authentication_status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def mid_status
|
def mid_status
|
||||||
|
@ -50,13 +46,34 @@ class Registrar::SessionsController < SessionsController
|
||||||
client.session_code = session[:mid_session_code]
|
client.session_code = session[:mid_session_code]
|
||||||
auth_status = client.authentication_status
|
auth_status = client.authentication_status
|
||||||
|
|
||||||
# binding.pry
|
case auth_status.status
|
||||||
# flash[:notice] = I18n.t('welcome')
|
when 'OUTSTANDING_TRANSACTION'
|
||||||
# flash.keep(:notice)
|
render json: { message: t('check_your_phone_for_confirmation_code') }, status: :ok
|
||||||
|
when 'USER_AUTHENTICATED'
|
||||||
# sign_in @user
|
@user = find_user_by_idc(session[:user_id_code])
|
||||||
# render js: "window.location = '#{registrar_invoices_path}'"
|
sign_in @user
|
||||||
render json: { message: t('not_ok') }, status: :request_timeout
|
flash[:notice] = t('welcome')
|
||||||
|
flash.keep(:notice)
|
||||||
|
render js: "window.location = '#{registrar_invoices_path}'"
|
||||||
|
when 'NOT_VALID'
|
||||||
|
render json: { message: t('user_signature_is_invalid') }, status: :bad_request
|
||||||
|
when 'EXPIRED_TRANSACTION'
|
||||||
|
render json: { message: t('session_timeout') }, status: :bad_request
|
||||||
|
when 'USER_CANCEL'
|
||||||
|
render json: { message: t('user_cancelled') }, status: :bad_request
|
||||||
|
when 'MID_NOT_READY'
|
||||||
|
render json: { message: t('mid_not_ready') }, status: :bad_request
|
||||||
|
when 'PHONE_ABSENT'
|
||||||
|
render json: { message: t('phone_absent') }, status: :bad_request
|
||||||
|
when 'SENDING_ERROR'
|
||||||
|
render json: { message: t('sending_error') }, status: :bad_request
|
||||||
|
when 'SIM_ERROR'
|
||||||
|
render json: { message: t('sim_error') }, status: :bad_request
|
||||||
|
when 'INTERNAL_ERROR'
|
||||||
|
render json: { message: t('internal_error') }, status: :bad_request
|
||||||
|
else
|
||||||
|
render json: { message: t('internal_error') }, status: :bad_request
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_user_by_idc(idc)
|
def find_user_by_idc(idc)
|
||||||
|
|
|
@ -10,21 +10,28 @@
|
||||||
%button.btn.btn-lg.btn-primary.btn-block.js-login{:type => 'submit'}= t('log_in')
|
%button.btn.btn-lg.btn-primary.btn-block.js-login{:type => 'submit'}= t('log_in')
|
||||||
|
|
||||||
:coffee
|
:coffee
|
||||||
|
$('.js-login').attr('disabled', false)
|
||||||
|
|
||||||
status_interval = null
|
status_interval = null
|
||||||
mid_status = () ->
|
mid_status = () ->
|
||||||
|
|
||||||
status_interval = setInterval((->
|
status_interval = setInterval((->
|
||||||
$.post('/registrar/login/mid_status').fail((data, bla, asd) ->
|
$.post('/registrar/login/mid_status').fail((data) ->
|
||||||
clearInterval(status_interval)
|
clearInterval(status_interval)
|
||||||
flash_alert(data.responseJSON.message)
|
flash_alert(data.responseJSON.message)
|
||||||
|
('.js-login').attr('disabled', false)
|
||||||
)
|
)
|
||||||
), 1000)
|
), 1000)
|
||||||
|
|
||||||
$('.js-login').on 'click', (e) ->
|
$('.js-login').on 'click', (e) ->
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
$(this).attr('disabled', true)
|
||||||
|
|
||||||
$.post($('form').attr('action'), $('form').serialize()).done((data) ->
|
$.post($('form').attr('action'), $('form').serialize()).done((data) ->
|
||||||
flash_notice(data.message)
|
if data.message
|
||||||
mid_status()
|
flash_notice(data.message)
|
||||||
|
mid_status()
|
||||||
|
).fail((data) ->
|
||||||
|
flash_alert(data.responseJSON.message)
|
||||||
|
$('.js-login').attr('disabled', false)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -498,3 +498,11 @@ en:
|
||||||
phone_no: 'Phone number'
|
phone_no: 'Phone number'
|
||||||
log_in_with_mid: 'Log in with mobile-id'
|
log_in_with_mid: 'Log in with mobile-id'
|
||||||
check_your_phone_for_confirmation_code: 'Check your phone for confirmation code'
|
check_your_phone_for_confirmation_code: 'Check your phone for confirmation code'
|
||||||
|
user_signature_is_invalid: 'User signature is invalid'
|
||||||
|
session_timeout: 'Session timeout'
|
||||||
|
user_cancelled: 'User cancelled'
|
||||||
|
mid_not_ready: 'M-ID is not ready, please try again'
|
||||||
|
phone_absent: 'User phone is not in coverage area'
|
||||||
|
sending_error: 'Could not send sms to user'
|
||||||
|
sim_error: 'SIM application error'
|
||||||
|
internal_error: 'Internal error'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue