Module: Truefactor::Controller::TruefactorizedMethods
- Defined in:
- lib/truefactor/controller.rb
Instance Method Summary collapse
- #redirect_to_truefactor(args) ⇒ Object
- #truefactor ⇒ Object
- #truefactor_approve!(challenge) ⇒ Object
- #truefactor_current_user ⇒ Object
- #truefactor_sign_in(user) ⇒ Object
- #truefactor_sign_out ⇒ Object
Instance Method Details
#redirect_to_truefactor(args) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/truefactor/controller.rb', line 99 def redirect_to_truefactor(args) origin = Truefactor.configuration.web_origin session[:truefactor_state] = SecureRandom.hex args[:state] = session[:truefactor_state] current_origin = "#{request.protocol}#{request.host_with_port}" args[:origin] = Truefactor.configuration.origin || current_origin args[:origin_name] = Truefactor.configuration.origin_name args[:icon] = Truefactor.configuration.icon redirect_to "#{origin}/#" + args.to_query end |
#truefactor ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/truefactor/controller.rb', line 14 def truefactor tfid_type = Truefactor.configuration.tfid_type if [:truefactor_state] && .delete(:truefactor_state) == params[:state] [:truefactor_response] = { value: params[:signs], expires: 1.hour.from_now } return render text: "Please close this window." elsif session[:truefactor_state] && session[:truefactor_state] == params[:state] session.delete :truefactor_state if params[:seeds] user = ::Truefactor._model_.find_by(tfid_type => params[:tfid]) if user flash[:alert] = "#{tfid_type} already exists" else user = ::Truefactor._model_.new puts tfid_type user.send "#{tfid_type}=", params[:tfid] user.truefactor = params[:seeds] user.save(validate: false) truefactor_sign_in user end return redirect_to '/' elsif params[:signs] if !session[:old_env] user = ::Truefactor._model_.find_by(tfid_type => params[:tfid]) v = if user && user.valid_truefactor?('login', params[:signs]) truefactor_sign_in user else flash[:alert] = "Invalid #{tfid_type} or signature" end return redirect_to '/' else session[:truefactor_signs] = params[:signs] return redirect_to session[:old_env]["path"]+'?'+session[:old_env]["params"].to_query end else raise "nothing" end else redirect_to_truefactor action: "register", tfid_type: Truefactor.configuration.tfid_type end end |
#truefactor_approve!(challenge) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/truefactor/controller.rb', line 77 def truefactor_approve!(challenge) path = request.env['PATH_INFO'] #url_for(action: params[:action], controller: params[:controller]) if session[:old_env] && session[:old_env]["path"] == path && session[:truefactor_signs] # we are back session.delete :old_env if truefactor_current_user.valid_truefactor?(challenge, session.delete(:truefactor_signs)) return true end end params.delete :action params.delete :controller session[:old_env] = { path: path, params: params } redirect_to_truefactor action: "auth", challenge: challenge false end |
#truefactor_current_user ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/truefactor/controller.rb', line 60 def truefactor_current_user if session[:user_id] @user ||= ::Truefactor._model_.find(session[:user_id]) else false end end |
#truefactor_sign_in(user) ⇒ Object
73 74 75 |
# File 'lib/truefactor/controller.rb', line 73 def truefactor_sign_in(user) session[:user_id] = user.id end |
#truefactor_sign_out ⇒ Object
68 69 70 71 |
# File 'lib/truefactor/controller.rb', line 68 def truefactor_sign_out session.clear redirect_to '/' end |