22
22
from app .models .email_notification import EmailNotification
23
23
from app .models .event_invoice import EventInvoice
24
24
from app .models .feedback import Feedback
25
- from app .models .mail import USER_REGISTER_WITH_PASSWORD
25
+ from app .models .mail import USER_REGISTER_WITH_PASSWORD , PASSWORD_RESET_AND_VERIFY
26
26
from app .models .notification import Notification
27
27
from app .models .session import Session
28
28
from app .models .speaker import Speaker
@@ -37,6 +37,7 @@ class UserList(ResourceList):
37
37
"""
38
38
List and create Users
39
39
"""
40
+
40
41
def before_create_object (self , data , view_kwargs ):
41
42
"""
42
43
method to check if there is an existing user with same email which is received in data to create a new user
@@ -58,12 +59,18 @@ def after_create_object(self, user, data, view_kwargs):
58
59
:param view_kwargs:
59
60
:return:
60
61
"""
61
- s = get_serializer ()
62
- hash = str (base64 .b64encode (str (s .dumps ([user .email , str_generator ()])).encode ()), 'utf-8' )
63
- link = make_frontend_url ('/verify' .format (id = user .id ), {'token' : hash })
64
- send_email_with_action (user , USER_REGISTER_WITH_PASSWORD , app_name = get_settings ()['app_name' ],
65
- email = user .email )
66
- send_email_confirmation (user .email , link )
62
+
63
+ if user .was_registered_with_order :
64
+ link = make_frontend_url ('/reset-password' , {'token' : user .reset_password })
65
+ send_email_with_action (user , PASSWORD_RESET_AND_VERIFY , app_name = get_settings ()['app_name' ],
66
+ email = user .email , link = link )
67
+ else :
68
+ s = get_serializer ()
69
+ hash = str (base64 .b64encode (str (s .dumps ([user .email , str_generator ()])).encode ()), 'utf-8' )
70
+ link = make_frontend_url ('/verify' .format (id = user .id ), {'token' : hash })
71
+ send_email_with_action (user , USER_REGISTER_WITH_PASSWORD , app_name = get_settings ()['app_name' ],
72
+ email = user .email )
73
+ send_email_confirmation (user .email , link )
67
74
68
75
if data .get ('original_image_url' ):
69
76
try :
@@ -90,6 +97,7 @@ class UserDetail(ResourceDetail):
90
97
"""
91
98
User detail by id
92
99
"""
100
+
93
101
def before_get (self , args , kwargs ):
94
102
95
103
if current_user .is_admin or current_user .is_super_admin or current_user :
@@ -221,11 +229,11 @@ def after_update_object(self, user, data, view_kwargs):
221
229
send_email_change_user_email (user , view_kwargs .get ('email_changed' ))
222
230
223
231
decorators = (api .has_permission ('is_user_itself' , fetch = "user_id,id" , fetch_as = "user_id" ,
224
- model = [Notification , Feedback , UsersEventsRoles , Session , EventInvoice , AccessCode ,
225
- DiscountCode , EmailNotification , Speaker , User ],
226
- fetch_key_url = "notification_id, feedback_id, users_events_role_id, session_id, \
232
+ model = [Notification , Feedback , UsersEventsRoles , Session , EventInvoice , AccessCode ,
233
+ DiscountCode , EmailNotification , Speaker , User ],
234
+ fetch_key_url = "notification_id, feedback_id, users_events_role_id, session_id, \
227
235
event_invoice_id, access_code_id, discount_code_id, email_notification_id, speaker_id, id" ,
228
- leave_if = lambda a : a .get ('attendee_id' )), )
236
+ leave_if = lambda a : a .get ('attendee_id' )),)
229
237
schema = UserSchema
230
238
data_layer = {'session' : db .session ,
231
239
'model' : User ,
@@ -240,7 +248,7 @@ class UserRelationship(ResourceRelationship):
240
248
"""
241
249
User Relationship
242
250
"""
243
- decorators = (is_user_itself , )
251
+ decorators = (is_user_itself ,)
244
252
schema = UserSchema
245
253
data_layer = {'session' : db .session ,
246
254
'model' : User }
0 commit comments