def post(self, request, *args, **kwargs): form = self.form(request.POST) if form.is_valid(): user_exists = SessionManager.get_user_by_username_or_email(strip_tags(request.POST['email'])) if user_exists: messages.error(request, '{} already has an account.'.format(user_exists.email)) else: new_app_user = AppUser() new_app_user.save() participant = ExchangeParticipant.get_or_create( appuser=new_app_user, giftexchange=self.giftexchange, status='pending' ) UserToken.clean(appuser=new_app_user, token_type='invitation') token = UserToken(appuser=new_app_user, token_type='invitation') token._generate_token() token.save() mailer = GifteratorMailer() mailer.send_exchange_invitation_email( request.POST['email'], self.giftexchange, existing_user=False, registration_token=token ) messages.success(request, 'An invitation has been sent to {}!'.format(request.POST['email'])) if settings.PREVIEW_EMAILS_IN_APP: self.context.update({'show_email': mailer}) self.context.update({'form': self.form()}) return HttpResponse(self.template.render(self.context, request))
def post(self, request, *args, **kwargs): form = PreRegisterUserForm(request.POST) if form.is_valid(): email_error = validate_email(request.POST['email'], 0) if email_error: error = '{}<p>Did you mean to <a href="{}">log in instead</a>?'.format( email_error, reverse('session_manager_login') ) messages.error(request, error) else: user = SessionManager.get_user_by_username_or_email(request.POST['email']) if not user: user, appuser = SessionManager.preregister_email(request.POST['email']) UserToken.clean(appuser=appuser, token_type='registration') token = UserToken(appuser=appuser, token_type='registration') token._generate_token() token.save() mailer = SessionManagerEmailer() mailer.send_app_registration_link(user, token) if settings.PREVIEW_EMAILS_IN_APP: self.context.update({'show_email': mailer}) messages.success(request, 'Thanks! To verify your email address, we have sent you a link to complete your registration.') return HttpResponse(self.template.render(self.context, request)) self.context.update({ 'form': form, }) return HttpResponse(self.template.render(self.context, request))
def post(self, request, *args, **kwargs): template = loader.get_template('session_manager/default.html') context = {} form = LoginEmailForm(request.POST) if form.is_valid(): user = SessionManager.get_user_by_username(request.POST['email']) UserToken.clean( token_type='reset', user=user ) reset_token = UserToken( token_type='reset', user=user ) reset_token._generate_token() reset_token.save() mailer = SessionManagerEmailer() mailer.send_password_reset_link(reset_token) messages.success( request, 'A password reset link was sent to {}. You have 48 hours to use it.'.format(reset_token.user.email) ) if settings.PREVIEW_EMAILS_IN_APP: context.update({'show_email': mailer}) else: messages.error(request, 'Could not validate request.') return HttpResponse(template.render(context, request))
def post(self, request, *args, **kwargs): form = self.form(request.POST) if form.is_valid(): existing_user = SessionManager.get_user_by_username_or_email(request.POST['email_address']) if existing_user: messages.error(request, 'This user is already registered.') self.context.update({'form': form}) return HttpResponse(self.template.render(self.context, request)) else: new_appuser = AppUser(registration_source='invitation') new_appuser.save() mailer = SessionManagerEmailer() UserToken.clean(appuser=new_appuser, token_type='invitation') invitation_token = UserToken( appuser=new_appuser, token_type='invitation', ) invitation_token._generate_token() invitation_token.save() mailer.send_app_invitation_link( to_email=request.POST['email_address'], from_appuser=self.appuser, token=invitation_token ) messages.success( request, 'You sent an invitation to {}!'.format(request.POST['email_address']) ) if settings.PREVIEW_EMAILS_IN_APP: self.context.update({'show_email': mailer}) self.context.update({'form': form}) return HttpResponse(self.template.render(self.context, request))
def post(self, request, *args, **kwargs): context = {} form = RegistrationLinkForm(request.POST) if form.is_valid(): user = SessionManager.get_user_by_username(request.POST['email']) UserToken.clean( token_type='registration', user=user ) registration_token = UserToken( token_type='registration', user=user ) registration_token._generate_token() registration_token.save() mailer = SessionManagerEmailer() mailer.send_app_registration_link(user, registration_token) messages.success( request, 'A registration link was sent to {}. Use the provided link to complete registration.'.format(registration_token.user.email) ) template = loader.get_template('session_manager/default.html') if settings.PREVIEW_EMAILS_IN_APP: context.update({'show_email': mailer}) return HttpResponse(template.render(context, request)) else: messages.error(request, 'Could not validate request.') return redirect(reverse('session_manager_login'))