Просмотр исходного кода

validate github emails & do not guess the domain for user ids when email are not present

Vladimir Kirillov 11 лет назад
Родитель
Сommit
ccb8644952
4 измененных файлов с 16 добавлено и 9 удалено
  1. 9 0
      src/avz_validator.erl
  2. 5 6
      src/github.erl
  3. 1 2
      src/microsoft.erl
  4. 1 1
      src/twitter.erl

+ 9 - 0
src/avz_validator.erl

@@ -0,0 +1,9 @@
+-module(avz_validator).
+-export([is_email/1]).
+
+is_email(Value) when is_list(Value) orelse is_binary(Value) ->
+    case re:run(Value, "^[a-zA-Z0-9!#$%&'*\+-/=\?^_`\.{|}~]+@[a-zA-Z0-9][a-zA-Z0-9\.-]+\.[a-zA-Z]+$") of
+        {match, _} -> true;
+        _ -> false
+    end;
+is_email(_) -> false.

+ 5 - 6
src/github.erl

@@ -61,12 +61,11 @@ registration_data(Props, github, Ori) ->
                     status = ok }}.
 
 email_prop(Props, github) ->
-        Mail = proplists:get_value(<<"email">>, Props),
-        error_logger:info_msg("Github Auth: Mail ~p Props ~p", [Mail,Props]),
-        case Mail of
-             null -> binary_to_list(proplists:get_value(<<"login">>, Props)) ++ "@github.com";
-             undefined -> binary_to_list(proplists:get_value(<<"login">>, Props)) ++ "@github.com";
-             M -> binary_to_list(M) end.
+    Mail = proplists:get_value(<<"email">>, Props),
+    case avz_validator:is_email(Mail) of
+        true -> Mail;
+        false -> binary_to_list(proplists:get_value(<<"login">>, Props)) ++ "@github"
+    end.
 
 login_button() -> #panel{ class=["btn-group"], body=
     #link{id=github_btn, class=[btn, "btn-large"], 

+ 1 - 2
src/microsoft.erl

@@ -23,7 +23,6 @@ api_event(_, Args, _)->
 registration_data(Props, microsoft, Ori)->
     error_logger:info_msg("Microsoft Login: ~p",[Props]),
     Id = proplists:get_value(<<"id">>, Props),
-    Name = proplists:get_value(<<"name">>, Props),
     GivenName = proplists:get_value(<<"first_name">>, Props),
     FamilyName = proplists:get_value(<<"last_name">>, Props),
     {Id, Ori#user{ display_name = proplists:get_value(<<"name">>, Props),
@@ -35,7 +34,7 @@ registration_data(Props, microsoft, Ori)->
                    sex = proplists:get_value(<<"gender">>, Props),
                    status = ok }}.
 
-email_prop(Props, _) -> binary_to_list(proplists:get_value(<<"id">>, Props)) ++ "@microsoft.com".
+email_prop(Props, _) -> binary_to_list(proplists:get_value(<<"id">>, Props)) ++ "@microsoft".
 
 login_button()-> #panel{class=["btn-group"], body=
     #link{id=microsoftbtn, class=[btn, "btn-microsoft", "btn-large"], 

+ 1 - 1
src/twitter.erl

@@ -22,7 +22,7 @@ registration_data(Props, twitter, Ori)->
                     register_date = erlang:now(),
                     status = ok }}.
 
-email_prop(Props, twitter) -> binary_to_list(proplists:get_value(<<"screen_name">>, Props)) ++ "@twitter.com".
+email_prop(Props, twitter) -> binary_to_list(proplists:get_value(<<"screen_name">>, Props)) ++ "@twitter".
 
 callback() ->
     Token = wf:q(<<"oauth_token">>),