def send_confirmation_and_redirect(request, email, task): if settings.DEBUG: url = utils.verification_url(email, task) return http.HttpResponse('<a href="%s">Click here to simulate the e-mail confirmation</a>.' % url) else: utils.send_verification_email(email, task) return http.HttpResponseRedirect('/accounts/email-sent/')
def _create_user(self, email, password, first_name, last_name, **extra_fields): """ Creates and saves a User with the given email and password. """ if not email: raise ValueError('The given email must be set') email = self.normalize_email(email) if not self.model: self.model = MHacksUser try: request = extra_fields.pop('request') except KeyError: request = None user = self.model(email=email, first_name=first_name, last_name=last_name, **extra_fields) user.set_password(password) user.save(using=self._db) from django.contrib.auth.models import Group user.groups.add(Group.objects.get(name=GroupEnum.HACKER)) user.save(using=self._db) from utils import send_verification_email if request: send_verification_email(user, request) return user
def send_confirmation_and_redirect(request, email, task): if settings.DEBUG: url = utils.verification_url(email, task) return http.HttpResponse( '<a href="%s">Click here to simulate the e-mail confirmation</a>.' % url) else: utils.send_verification_email(email, task) return http.HttpResponseRedirect('/accounts/email-sent/')
def activate(): # Called if account tries to login and the email address was not yet activated. form = ValidateEmailForm() if form.validate_on_submit(): my_id = session["validate_user_id"] email = form.email.data.strip() token = s.dumps(form.email.data, salt=app.config['SALT']) user = User.query.filter(User.id == my_id).first() # Make sure submitted email address does not belong to another user. if user.email == email: user.verification_token = token # print(token, len(token)) db.session.commit() send_verification_email(email, token) flash(u'Please check your email for a verification link.', 'alert-success') return redirect((url_for("index"))) else: email_exists = User.query.filter(User.email == email).first() if email_exists: # This email already exists in the DB and is used by another user. Show error. flash( u'This email address is already in use. Please submit another.', 'alert-danger') return render_template('register.html', title="Register", object="email", form=form, email=email) else: # This email address does not exist in the DB. Let this user register it. user.verification_token = token user.email = email # print(token, len(token)) db.session.commit() send_verification_email(email, token) flash(u'Please check your email for a verification link.', 'alert-success') return redirect((url_for("index"))) else: # form errors return render_template('register.html', form=form, title="Activate", object="email")
def handle_setup(req_obj, flag): uid = req_obj['email'] # registration if flag == "True": # if user already exists, fail # if no more wallets available, fail if uid in user_dict: # utils.send_verification_email(uid, user_dict[uid]['pwd']) return 1 # else assign user with a wallet else: pwd = ''.join( random.SystemRandom().choice(string.digits) for _ in range(4)) if SEND_OTP: if utils.send_verification_email(uid, pwd) == 1: return 1 user_dict[uid] = {"pwd": pwd, "wallet":uid} if registerUser(user_dict[uid]['wallet']) != 0: user_dict.pop(uid) return 1 utils.write_file(db_path, json.dumps(user_dict)) return 0
def add_user(): # NO LONGER USER. REPLACED WITH /REGISTER. form = RegisterUserForm() if form.validate_on_submit(): username = form.username.data.strip() email = form.email.data.strip() password = form.password.data.strip() hashed_password = generate_password_hash(password, method='sha256') level = 100 token = s.dumps(form.email.data, salt=app.config['SALT']) # Check for existence of username and email address. username_exists = User.query.filter(User.username == username).first() if username_exists: flash(u'Username already exists', 'alert-danger') return render_template('register.html', form=form, object="user", title="Register") email_exists = User.query.filter(User.email == email).first() if email_exists: flash(u'Email already exists', 'alert-danger') return render_template('register.html', form=form, object="user", title="Register") try: new_user = User(username=username, email=email, level=level, password=hashed_password, created_at=datetime.utcnow(), verification_token=token) db.session.add(new_user) db.session.commit() except exc.IntegrityError: flash(u'DB Integrity error.', 'alert-danger' ) # Should never occur since we already check for dupes. return render_template('register.html', form=form, object="user", title="Register") except exc.OperationalError: flash(u'DB failure.', 'alert-danger') # Is DB down? Does table exist? return render_template('register.html', form=form, object="user", title="Register") except Exception as e: print(e) flash(u'Unhandled database exception.', 'alert-danger') return render_template('register.html', form=form, object="user", title="Register") send_verification_email(email, token) flash(u'User added', 'alert-success') return redirect((url_for("view_users"))) else: # return "<h1>Error</h1>" return render_template('register.html', form=form, object="user", title="Register")
def send_confirmation_and_redirect(request, email, task): utils.send_verification_email(email, task) return http.HttpResponseRedirect(reverse('accounts-email-sent'))