13
13
from ..ext .identitytoolkit import Gitkit
14
14
from itsdangerous import URLSafeTimedSerializer
15
15
16
- from ..model import Account , Challenge , Repository , Roles , Site , Sites , db
16
+ from ..model import Account , OobAction , Repository , Roles , Site , Sites , db
17
17
from .base import app , mailgun , jsonp
18
18
19
19
@@ -125,10 +125,10 @@ def widget():
125
125
oob_code = parse_qs (url .query ).get ('oobCode' )
126
126
if not oob_code or len (oob_code ) != 1 :
127
127
abort (400 )
128
- challenge = Challenge .query .get (oob_code [0 ])
129
- if challenge is None :
128
+ action = OobAction .query .get (oob_code [0 ])
129
+ if action is None :
130
130
abort (400 )
131
- base_url = Sites (challenge .site_id ).get_base_url ()
131
+ base_url = Sites (action .site_id ).get_base_url ()
132
132
if not base_url .endswith ('/' ):
133
133
base_url += '/'
134
134
return redirect ('{}#sign-in' .format (base_url ))
@@ -155,12 +155,11 @@ def sign_in_success(site_id):
155
155
db .session .commit ()
156
156
return render_template ('auth/close-window.html' , message = 'You have signed in.' )
157
157
oob_link = gitkit .get_email_verification_link (email )
158
- challenge = Challenge (
158
+ action = OobAction (
159
159
oob_code = parse_qs (urlparse (oob_link ).query )['oobCode' ][0 ],
160
160
site_id = site_id ,
161
- account_id = account .id ,
162
161
moment = datetime .utcnow ())
163
- db .session .add (challenge )
162
+ db .session .add (action )
164
163
db .session .commit ()
165
164
text = render_template ('auth/verify-email.txt' , oob_link = oob_link )
166
165
send (email , 'Verify email address' , text )
@@ -179,7 +178,29 @@ def sign_out():
179
178
180
179
@blueprint .route ('/oob-action' , methods = {'POST' })
181
180
def oob_action ():
181
+ url_adapter = _request_ctx_stack .top .url_adapter
182
+ url = urlparse (request .referrer )
183
+ if url .netloc != request .host :
184
+ abort (400 )
185
+ endpoint , __ = url_adapter .match (url .path , 'GET' )
186
+ if endpoint != 'auth.widget' :
187
+ abort (400 )
188
+ next = parse_qs (url .query ).get ('next' )
189
+ if not next or len (next ) != 1 :
190
+ abort (400 )
191
+ url = urlparse (next [0 ])
192
+ if url .netloc != request .host :
193
+ abort (400 )
194
+ endpoint , values = url_adapter .match (url .path , 'GET' )
195
+ if endpoint != 'auth.sign_in_success' :
196
+ abort (400 )
182
197
result = gitkit .get_oob_result ()
198
+ action = OobAction (
199
+ oob_code = parse_qs (urlparse (result ['oob_link' ]).query )['oobCode' ][0 ],
200
+ site_id = values ['site_id' ],
201
+ moment = datetime .utcnow ())
202
+ db .session .add (action )
203
+ db .session .commit ()
183
204
if result ['action' ] == 'changeEmail' :
184
205
text = render_template (
185
206
'auth/change-email.txt' ,
0 commit comments