Changeset 8bae554 in OpenWorkouts-current for ow/views/user.py
- Timestamp:
- Feb 21, 2019, 9:54:45 PM (5 years ago)
- Branches:
- current, feature/docs, master
- Children:
- d411dae
- Parents:
- 38171c6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/views/user.py
r38171c6 r8bae554 50 50 renderer='ow:templates/login.pt') 51 51 def login(context, request): 52 message = '' 53 email = '' 52 # messages is a dict of pre-defined messages we would need to show to the 53 # user when coming back to the login page after certain actions 54 messages = { 55 'already-verified': _('User has been verified already'), 56 'link-sent': _('Verification link sent, please check your inbox'), 57 'max-tokens-sent': _( 58 'We already sent you the verification link more than three times') 59 } 60 message = request.GET.get('message', '') 61 if message: 62 message = messages.get(message, '') 63 email = request.GET.get('email', '') 54 64 password = '' 55 65 return_to = request.params.get('return_to') 56 66 redirect_url = return_to or request.resource_url(request.root) 67 # If the user still has to verify the account, this will be set to the 68 # proper link to re-send the verification email 69 resend_verify_link = None 57 70 58 71 if 'submit' in request.POST: … … 70 83 else: 71 84 message = _('You have to verify your account first') 85 resend_verify_link = request.resource_url( 86 user, 'resend-verification-link' 87 ) 72 88 else: 73 89 message = _('Wrong email address') … … 77 93 'email': email, 78 94 'password': password, 79 'redirect_url': redirect_url 95 'redirect_url': redirect_url, 96 'resend_verify_link': resend_verify_link 80 97 } 81 98 … … 103 120 # send a verification link to the user email address 104 121 send_verification_email(request, user) 122 user.verification_tokens_sent += 1 105 123 # Send to login 106 124 return HTTPFound(location=request.resource_url(context)) … … 135 153 # if we can not verify the user, show a page with some info about it 136 154 return {} 155 156 157 @view_config( 158 context=User, 159 name="resend-verification-link") 160 def resend_verification_link(context, request): 161 """ 162 Send an email with the verification link, only if the user has not 163 been verified yet 164 """ 165 # the message to be shown when the user gets back to the login page 166 query = {'message': 'already-verified'} 167 if not context.verified: 168 tokens_sent = getattr(context, 'verification_tokens_sent', 0) 169 if tokens_sent > 3: 170 # we already sent the token 3 times, we don't send it anymore 171 query = {'message': 'max-tokens-sent', 'email': context.email} 172 else: 173 if context.verification_token is None: 174 # for some reason the verification token is not there, get one 175 context.verification_token = get_verification_token() 176 send_verification_email(request, context) 177 context.verification_tokens_sent = tokens_sent + 1 178 query = {'message': 'link-sent', 'email': context.email} 179 # Send to login 180 url = request.resource_url(request.root, 'login', query=query) 181 return HTTPFound(location=url) 137 182 138 183
Note: See TracChangeset
for help on using the changeset viewer.