def create_account(): form = NewUser() if form.validate_on_submit(): if User.query.filter_by(email=form.email.data).order_by(User.member_since.desc()).first(): flash('Email already registered!') else: # CREATE USER user = User(email=form.email.data, password=form.email.data, username=form.email.data, name=form.first_name.data + " " + form.last_name.data) db.session.add(user) db.session.commit() # GET SECURITY TOKEN token = ts.dumps(form.email.data, salt='email-confirm-key') confirm_url = url_for('auth.confirm_email', token=token, _external=True) # WRITE CONFIRMATION EMAIL AND SEND msg = Message(subject='Registration Confirmation for carminati.io!', sender='*****@*****.**', recipients=[form.email.data]) msg.body = """ Hey {first_name}, Thanks for registering for my site! Please confirm your email with the link below: {confirm} -Anthony """.format(first_name=form.first_name.data, confirm=confirm_url) mail.send(msg) flash('Confirmation email sent!') return redirect(url_for('site.index')) return render_template('auth/register.html', form=form)
def createUser(): '''Will create a new user and add their background/profile pic to static folder''' form = NewUser() if form.validate_on_submit(): try: if form.password.data != form.reenter.data: raise ValueError user = User.signup( username=form.username.data, password=form.password.data, email=form.email.data, bio=form.bio.data, filename_image=photos.save(form.profilepic.data), background_image=photos.save(form.background.data), ) #will save photos to static folder db.session.commit() except IntegrityError: flash("Info is not correctly filled", 'danger') return render_template('createuser.html', form=form) except ValueError: flash("Password must match", 'danger') return render_template('createuser.html', form=form) do_login(user) #adds user to global add_user_to_g() return redirect(f"/{g.user.id}") else: return render_template('createuser.html', form=form)
def create_account(): form = NewUser() if form.validate_on_submit(): if User.query.filter_by(email=form.email.data).order_by( User.member_since.desc()).first(): flash('Email already registered!') else: # CREATE USER user = User(email=form.email.data, password=form.email.data, username=form.email.data, name=form.first_name.data + " " + form.last_name.data) db.session.add(user) db.session.commit() # GET SECURITY TOKEN token = ts.dumps(form.email.data, salt='email-confirm-key') confirm_url = url_for('auth.confirm_email', token=token, _external=True) # WRITE CONFIRMATION EMAIL AND SEND msg = Message( subject='Registration Confirmation for carminati.io!', sender='*****@*****.**', recipients=[form.email.data]) msg.body = """ Hey {first_name}, Thanks for registering for my site! Please confirm your email with the link below: {confirm} -Anthony """.format(first_name=form.first_name.data, confirm=confirm_url) mail.send(msg) flash('Confirmation email sent!') return redirect(url_for('site.index')) return render_template('auth/register.html', form=form)
def add_labeller(): '''Agregar usuario''' form = NewUser() tasks = Task.query.all() roles = Role.query.all() form.taskid.choices=[(task.id,task.name) for task in tasks] form.roleids.choices=[(role.id,role.name) for role in roles] if form.cancel.data: return redirect(url_for('.index')) elif form.validate_on_submit(): nuser = User( username=form.username.data, active=True, name=form.name.data, taskid=form.taskid.data, password=user_manager.hash_password(form.password.data)) for role_id in form.roleids.data: role = Role.query.filter(Role.id==role_id).first() if role: nuser.roles.append(role) db.session.add(nuser) db.session.commit() return redirect(url_for('.index')) return render_template("newlabeller.html", form=form)
def newuser(): form = NewUser() if form.validate_on_submit(): flash('Login requested for user {}'.format(form.name.data, )) return redirect(url_for('dashboard')) return render_template('new_user.html', title='create new user', form=form)