File tree 1 file changed +20
-2
lines changed
1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 7
7
from app .email import send_password_reset_email
8
8
from datetime import datetime
9
9
from werkzeug .urls import url_parse
10
- from oauth import OAuthSignIn
10
+ from app . oauth import OAuthSignIn
11
11
12
12
13
13
@app .route ('/' )
@@ -94,7 +94,25 @@ def before_request():
94
94
95
95
@app .route ('/authorize/<provider>' )
96
96
def oauth_authorize (provider ):
97
- if not current_user .is_anonymous () :
97
+ if not current_user .is_anonymous :
98
98
return redirect (url_for ('index' ))
99
99
oauth = OAuthSignIn .get_provider (provider )
100
100
return oauth .authorize ()
101
+
102
+
103
+ @app .route ('/callback/<provider>' )
104
+ def oauth_callback (provider ):
105
+ if not current_user .is_anonymous :
106
+ return redirect (url_for ('index' ))
107
+ oauth = OAuthSignIn .get_provider (provider )
108
+ social_id , username , email = oauth .callback ()
109
+ if social_id is None :
110
+ flash ('Authentication failed' )
111
+ return redirect (url_for (index ))
112
+ user = User .query .filter_by (social_id = social_id ).first ()
113
+ if not user :
114
+ user = User (social_id = social_id , nickname = username , email = email )
115
+ db .session .add (user )
116
+ db .session .commit ()
117
+ login_user (user , True )
118
+ return redirect (url_for ('index' ))
You can’t perform that action at this time.
0 commit comments