Commits

Anonymous committed 12db5fb

fixes

  • Participants
  • Parent commits 63ba0e8

Comments (0)

Files changed (1)

File resources/resource_openid_login.erl

 -include_lib("webmachine_resource.hrl").
 -include_lib("include/zotonic.hrl").
 
+-define(MOD, mod_openid).
+
 init(DispatchArgs) ->
     {ok, DispatchArgs}.
 
 moved_temporarily(ReqData, Context) ->
     Context1 = ?WM_REQ(ReqData, Context),
     Context2 = z_context:ensure_all(Context1),
-    {Location, Context3} = case mod_openid:process_return(Context2) of
+    {Location, Context3} = case ?MOD:process_return(Context2) of
 	{ok, UserId} when is_integer(UserId) ->	%% already a user, logon him/her
 	    {ok, ContextLogon} = z_auth:logon(UserId, Context2),
 	    {get_ready_page_logon(ContextLogon), ContextLogon};
 	    ?LOG("OpenID login failed on return: ~p", [E]),
 	    z_dispatcher:url_for(logon, [{openid, error}, {openid_error, E}], Context2)
     end,
-    {{true, Location}, ReqData, Context3}.
+    ?WM_REPLY({true, Location}, Context3).
 
 
 %% @doc send anonymous user to remote server for authentification
 event({submit, step1, _TriggerId, _TargetId}, Context) ->
     OpenIdUrl = z_context:get_q(openid_url, Context),
-    case mod_openid:get_redirect_url(OpenIdUrl, Context) of
-	{ok, RedirectUrl} -> 
-	    z_render:wire({redirect, [{location, RedirectUrl}]}, Context);
-	{error, E}	  -> 
-	    [ErrorMsg] = io_lib:format("~p", [E]),
-	    z_render:growl_error("Error: " ++ ErrorMsg, Context)
+    case try ?MOD:get_redirect_url(OpenIdUrl, Context) catch _:E -> {error, E} end of
+	{ok, RedirectUrl} -> z_render:wire({redirect, [{location, RedirectUrl}]}, Context);
+	{error, E1}	  -> render_error(E1, Context)
     end.
 
 
 	Url -> Url
     end.
 
+%% @doc by now, RscProps usually contain a trash. To fix it (empty it?) look for filters:
+prepare_signup_rsc_props(RscProps, Context) ->
+    case z_notifier:first({prepare_signup_rsc_props, {?MOD, RscProps}}, Context) of
+	undefined -> RscProps;
+	RscProps1 -> RscProps1
+    end.
 
 %% @doc do a user signup action
 %% @spec signup_user(RscProps, IdentProps, Context) -> {RedirectUrl, Context1}
 signup_user(RscProps, SignupProps, Context) ->
-    signup_user(get_signup_method(Context), RscProps, SignupProps, Context).
+    signup_user(get_signup_method(Context), prepare_signup_rsc_props(RscProps, Context), SignupProps, Context).
 
 %% @doc redirect user to mod_signup/signup.tpl or compatible. Transfer ident data via z_session.
 signup_user(xs, RscProps, SignupProps, Context) ->
 
 %% @doc look into config to observe user signup route
 get_signup_method(Context) ->
-    z_convert:to_atom(m_config:get_value(?MODULE, signup_method, 'fast', Context)).
+    z_convert:to_atom(m_config:get_value(?MOD, signup_method, 'fast', Context)).
+
+
+format_error({timeout, _})		  -> timeout;
+format_error({error, X}) when is_atom(X)  -> X;
+format_error(_)				  -> "unknown error".
+
+
+render_error(E, Context) ->
+    Ef = format_error(E),
+    case z_notifier:first({render_logon_error, {?MOD, Ef}}, Context) of
+	undefined ->
+	    ErrorMsg = io_lib:format("Error: ~p", [Ef]),
+	    z_render:growl_error(ErrorMsg, Context);
+
+	#context{}=Context1   -> Context1
+    end.
+