Beispiel #1
0
def register():
    '''
    Handle registering
    Use get requests to handle registering page
    Use post requests to handle creation of accounts
    '''
    form = RegisterForm()
    
    #if they haven't filled out the form, send them the form with a reminder
    if not form.validate_on_submit() and request.method == 'POST':
        return render_template('register.html', form=form, message='Please'
	                                        ' enter username and password.')
    elif not form.validate_on_submit():
        return render_template('register.html', form=form, message=None)
	
    #don't let the user create a duplicate username
    else:
	    attempted_name = form.username.data
	    if User.query.filter(User.username == attempted_name).first():
	        return render_template('register.html', form=form, 
	                                message='Username already taken.')
	    else:
	        user = db_utilities.create_user(form.username.data, form.password.data)
	        login_user(user)
	        return redirect(url_for('home'))
Beispiel #2
0
def register():
    form = RegisterForm()

    if form.validate_on_submit():
        Username = User.make_unique_username( form.Username.data )
        Password = form.Password.data
        Email = form.email.data
        user = User(
                username = Username,
                email = Email,
                role = ROLE_USER,
                password = Password
                )
        db.session.add( user )
        db.session.commit()

        login_user(user)

        return flask.redirect( flask.request.args.get('next') or
                        flask.url_for('main.index')
                        )

    return flask.render_template('register.html',
            title = "Sign Up",
            form = form)
Beispiel #3
0
def register():
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        user = User(
            country_code=form.country_code.data,
            phone=form.phone.data
        )
        db.session.add(user)
        db.session.commit()

        # generate otp and add it to db
        otp_num = randint(1000, 9999)
        otp = OTP(
            otp_num = otp_num,
            expires_at = (datetime.now() + timedelta(minutes = 3)),
            user_id = user.id
        )
        db.session.add(otp)
        db.session.commit()

        #send sms
        to = user.country_code + user.phone
        msg = str(otp_num)
        print(to)
        print(msg)
        nexmo.send_message({'from': '12076138822', 'to': to, 'text': msg})
        flash('تم إرسال رمز التحقق لجوال رقم ({})'.format(user.country_code+
                user.phone), 'info')
        print(user.id)
        return redirect(url_for('verify', user_id=user.id))
        #login_user(user)
        #flash('Thank you for registering.', 'success')
        #return redirect(url_for('index'))
    return render_template('register.html', form=form)
Beispiel #4
0
def login():
	message_box = ""
	login_form = LoginForm(prefix="login")
	register_form = RegisterForm(prefix="register")

	#Only validate forms if the user pressed one of the submit buttons
	if 'submit_button' in request.form:
		if request.form['submit_button'] == 'Login':
			if login_form.validate_on_submit():
				user = User.query.filter_by(username = request.form['login-username'].strip()).first()
				if user == None or user.password != request.form['login-password'].strip():
					message_box = message_box_html('Username / Password combination is invalid.', error=True)
				else:
					login_user(user)
					return redirect(url_for('workspace'))
			else:
				message_box = get_form_error(login_form)
		elif request.form['submit_button'] == 'Register':
			if register_form.validate_on_submit():
				if User.query.filter_by(username = request.form['register-username'].strip()).first() != None:
					message_box = message_box_html('Username already in use.', error=True)
				elif User.query.filter_by(email = request.form['register-email'].strip()).first():
					message_box = message_box_html('Email address already in use.', error=True)
				else:
					new_user = User()
					new_user.username = request.form['register-username'].strip()
					new_user.password = request.form['register-password'].strip()
					new_user.email = request.form['register-email'].strip()
					db.session.add(new_user)
					db.session.commit()
					message_box = message_box_html('Your account has been created.')
			else:	#Set error message to the first validation error.
				message_box = get_form_error(register_form)
	
	return render_template('login.html', login_form=login_form, register_form=register_form, message_box=message_box)
Beispiel #5
0
def register():
    error = []
    form = RegisterForm(flask.request.form)
    if flask.request.method == "POST":
        if form.validate_on_submit():
            new_user = User(
                form.name.data,
                form.email.data,
                form.password.data
            )
            try:
                db.session.add(new_user)
                db.session.commit()
                flask.flash("Thanks for registering. Please login.")
                return flask.redirect(flask.url_for("login"))
            except IntegrityError:
                error.append("That username and/or email already exists.")
                return flask.render_template(
                    "register.html", form = form, error = error)
        else:
            if len(form.name.data) < 6:
                error.append("Username must be greater than 6 characters.")
            if len(form.email.data) < 6:
                error.append("Email must be greater than 6 characters.")
            if len(form.password.data) < 6:
                error.append("Password must be greater than 6 characters.")
            if form.password.data != form.confirm.data:
                error.append("Passwords must match!")
    return flask.render_template("register.html", form=form, error=error)
Beispiel #6
0
def register():
    error = None
    form = RegisterForm()
    next = get_redirect_target()
    next = retain_before_auth_page(next)
    if request.method == 'POST':
        if request.form['submit'] == 'cancel':
            return redirect_back('index')
        else:
            if form.validate_on_submit():
                user = User(
                    username=form.username.data,
                    email=form.email.data,
                    password=bcrypt.generate_password_hash(form.password.data)
                )
                db.session.add(user)
                db.session.commit()

                """"
                if not form.email.data:
                    user=User.query.filter_by(username=form.username.data).first()
                    user.email = 'defaultemail_' + str(user.id) + '@gmail.com'
                    db.session.add(user)
                    db.session.commit()
                """""

                login_user(user)
                flash('You were logged in. ', 'success')

                return redirect_back('index')
            else:
                flash('Invalid email or password.', 'danger')
                return render_template('register.html', form=form, error=error, next=next)
    else:
        return render_template('register.html', form=form, error=error, next=next)
def register():
    form = RegisterForm(request.form)
    # Validate inputs
    if form.validate_on_submit():
        # Make a new database record

        try:
            response = requests.post(api_endpoint('register-user'),
                                    data={'email': form.email.data,
                                          'password': form.password.data
                                    }
            )
                
            if response.status_code == 201:
                
                flash('Registered {} successfully! Please log in to continue.'.format(form.email.data),'success')
                
                next = request.args.get('next')
                # next_is_valid should check if the user has valid
                # permission to access the `next` url
                # if not next_is_valid(next):
                #     return abort(400)
                
                return redirect(next or url_for('login'))
            
            elif response.status_code == 406:
                flash('E-mail address already registered, please use a different e-mail address.', 'danger')
            else:
                flash('Status {}: Registration failed, please try again later.'.format(response.status_code), 'danger')
        except ConnectionError as ex:
            flash('Failed to connect to registration server. Please try again later.', 'danger')


    return render_template('register.htm', app_name=APP_NAME, page='Register', form=form)
Beispiel #8
0
def register():
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        print form.data
        user = User(
            email=form.email.data,
            password=form.password.data,
            email_confirmed=False,
            extension='{}'
        )
        db.session.add(user)
        db.session.commit()

        target = redirect(url_for('index'))
        response = app.make_response(target)
        response.set_cookie('current_user_email', value=user.email)

        token = generate_confirmation_token(user.email)
        confirm_url = url_for('confirm_email', token=token, _external=True)
        html = render_template('user/activate.html', confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_email(user.email, subject, html)

        login_user(user)
        flash('You registered and are now logged in. Welcome!', 'success')

        return response
    return render_template('user/register.html', form=form)
Beispiel #9
0
def register():
    form = RegisterForm()

    if request.method == 'POST':

        if not form.validate_on_submit():
            flash('Invalid name or/and password', 'danger')
            return _render_template('join.html', form=form)

        r = requests.put(api_url + '/user',
                         headers=headers,
                         data=json.dumps({'username': form.username.data,
                                          'password': form.password.data}))

        # Successfully registration
        if r.status_code == 201:
            r = requests.get(api_url + '/token',
                             headers=headers,
                             auth=(form.username.data + '@' + cfg.AppConfig['MAIL_DOMAIN'], form.password.data))
            data = json.loads(r.text)
            session['user'] = User(id=data['id'], username=data['username'], token=data['token']).__dict__
            return redirect(url_for('get_all_mails'))

        # Errors
        flash(json.loads(r.text)['error'], 'danger')
        return _render_template('join.html', form=form)

    else:
        return _render_template('join.html', form=form)
Beispiel #10
0
def register():
    form = RegisterForm(request.form)

    if form.validate_on_submit():
        try:
            response = requests.post(
                api_endpoint("user"),
                data={
                    "email": form.email.data,
                    "password": form.password.data,
                    "first_name": form.first_name.data,
                    "last_name": form.last_name.data,
                },
            )

            if response.status_code == 201:

                flash("Registered {} successfully! Please log in to continue.".format(form.email.data), "success")

                next = request.args.get("next")
                # next_is_valid should check if the user has valid
                # permission to access the `next` url
                # if not next_is_valid(next):
                #     return abort(400)

                return redirect(next or url_for("login"))

            elif response.status_code == 406:
                flash("E-mail address already registered, please use a different e-mail address.", "danger")
            else:
                flash("Status {}: Registration failed, please try again later.".format(response.status_code), "danger")
        except ConnectionError as ex:
            flash("Failed to connect to registration server. Please try again later.", "danger")

    return render_template("register.htm", app_name=APP_NAME, page="Register", form=form)
Beispiel #11
0
def registro():
    form = RegisterForm()
    if form.validate_on_submit():
        nombre = form.nombre.data
        print nombre
        form.nombre.data = 'Es otro german'
    return render_template
Beispiel #12
0
def sign_up():
    form = RegisterForm()
    if form.validate_on_submit():
        # new catalog for user
        catalog_name = str(form.data['login'] + "_main")
        new_dir = dbTables.Catalog(catalog_name)
        db_connection.session.add(new_dir)
        db_connection.session.commit()
        # new filespace for user
        fs_name = str(form.data['login'] + "_fs")
        new_fs = dbTables.FileSpace(fs_name, new_dir)
        db_connection.session.add(new_fs)
        db_connection.session.commit()
        fs = db_connection.session.execute(
            sqlalchemy.select([dbTables.FileSpace])
                      .where(dbTables.FileSpace.storage_name == fs_name))
        fs = fs.fetchone()
        time_is = datetime.datetime.strptime(strftime("%d-%m-%Y", gmtime()),
                                             "%d-%m-%Y").date()
        time_is = time_is + datetime.timedelta(days=365)
        date_max = time_is.strftime("%Y-%m-%d")
        id_new = db_connection.session.execute(
            sqlalchemy.func.count(dbTables.Users.id)
        ).fetchone()[0] + 1
        password_hash = str(sha256(form.data['password'] +
                                   str(id_new)).hexdigest())
        # create new user
        new_user = dbTables.Users(form.data['login'], form.data['fullname'],
                                  password_hash, form.data['email'],
                                  date_max, 1, 2, fs.id)
        db_connection.session.add(new_user)
        db_connection.session.commit()
        return redirect(url_for('success'))
    return render_template('sign-up.html', title=u"Регистрация", form=form)
def register():
    if session.get("username"):
        flash("Youur are already logged in", "info")
        redirect(url_for("manager.index"))

    form = RegisterForm()
    if form.validate_on_submit():
        username = request.form.get("username")
        password = request.form.get("password")
        name = request.form.get("name")
        email = request.form.get("email")

        existing_username = User.get(username=username)
        if existing_username:
            flash(
                "Username {} already existst in the database".format(username), "error")
            return render_template("register.html", form=form)

        user = User(
            username=username,
            name=name,
            email=email,
            password=password
        )
        flash('You are now registered. Please login.', 'success')
        return redirect(url_for("auth.login"))
    return render_template("register.html", form=form)
Beispiel #14
0
def register():
	if g.user is not None and g.user.is_authenticated():
		return redirect(url_for('intro'))
	form = RegisterForm()
	error = None
	if form.validate_on_submit():
		firstname = form.firstname.data
		lastname = form.lastname.data
		email = form.email.data.lower()
		password = form.password.data
		confirm_password = form.confirm_password.data
		activate = False
		pic = '';

		user = User.query.filter_by(email=email).first()
		if '@' not in email or '.' not in email:
			flash('Invalid email. Please try again.')
		elif User.query.filter_by(email=email).first() is not None:
			flash('Email is already registered.')
		elif password != confirm_password:
			flash('Please check confirm password')
		else:
			user = User(firstname=firstname, lastname=lastname, email=email,
						password=password, pic=pic, activate=activate)
			db.session.add(user);
			db.session.commit()
			service.send_activate(user)
			return render_template('welcome.html')
	return render_template('register.html', title='Register', form=form)
Beispiel #15
0
def register():
    if _user_is_authenticated():
        return redirect('/')

    form = RegisterForm()
    if form.validate_on_submit():
        if dbsession.query(
                exists().where(User.email == form.email.data)).scalar():
            warning_markup = Markup(
                'User with email %(email) already exists. '
                'Click <a href="%(login_link)">here</a> to login.',
                email=form.email.data, login_link=url_for('login'))
            flash(warning_markup, 'warning')
            return render_template('register.html', form=form)
        user = User(name=form.name.data,
                    email=form.email.data,
                    password_hash=bcrypt.encrypt(form.password.data))
        dbsession.add(user)
        dbsession.commit()
        login_user(user, remember=True)
        return redirect('/')
    else:
        write_errors_to_flash(form)

    return render_template('register.html', form=form)
Beispiel #16
0
def register():
    register_form = RegisterForm()
    data = {
        'title': 'Register',
        'form': register_form,
    }

    if register_form.validate_on_submit():
        # get data from form
        username = register_form.username.data
        password = register_form.password.data
        confirm_password = register_form.confirmPassword.data
        email = register_form.email.data

        # check data
        if len(username) < 2:
            flash(u'用户名长度不能小于2!', 'danger')
            return redirect(url_for('register'))
        if password != confirm_password:
            flash(u'两次密码不匹配!', 'danger')
            return redirect(url_for('register'))
        if len(password) < 6:
            flash(u'密码长度不能小于6!', 'danger')
            return redirect(url_for('register'))
        if not re.match(r'\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*', email):
            flash(u'Email地址不规范!', 'danger')
            return redirect(url_for('register'))

        # Check Username is already register
        user = Users.query.filter_by(username=username).first()
        if user is not None or user:
            flash(u'用户名已存在!', 'danger')
            return redirect(url_for('register'))

        # Insert into database
        user = Users(id="", username=username, email=email, password=password)
        db.session.add(user)
        db.session.commit()
        user = Users.query.filter_by(username=username).first_or_404()
        tid = user.id
        users_info = UsersInfo(id="", user_id=tid,
                               register_time="", last_login_time="", last_login_ip=request.remote_addr,
                               token=random_str(32), is_active=0, qiniu_have_account=0, qiniu_access_key=None,
                               qiniu_secret_key=None, qiniu_bucket_name=None, qiniu_domain=None)
        db.session.add(users_info)
        db.session.commit()

        session['user_id'] = tid

        # Send mail
        s = Serializer(app.config['SECRET_KEY'], 3600)
        token = s.dumps({'user_id': tid})

        send_mail(email, ' Please confirm your account',
                  'mail/confirm', username=username, token=token)

        # return result
        flash(u'注册成功!请到邮箱查看验证邮件,验证通过后方可登录。', 'success')
        return redirect(url_for('register'))
    return render_template("register.html", data=data)
Beispiel #17
0
def register():
	if g.user is not None and g.user.is_authenticated():
		flash('You\'re already logged in.')
		return redirect(url_for('index'))
	form = RegisterForm()
	if form.validate_on_submit():
		if User.query.filter_by(email = form.email.data).first() != None:
			flash('This email is already registered.  Login instead.')
			return(redirect(url_for('login')))
		if User.query.filter_by(name = form.name.data).first() != None:
			flash('That name is taken.  Try another.')
			return render_template('register.html', form = form)
		email = form.email.data
		name = form.name.data
		passhash = hashlib.sha224(form.pswd.data + form.email.data).hexdigest()
		user = User(email = email, name = name, passhash = passhash, role = ROLE_USER)
		db.session.add(user)
		db.session.commit()
		default = Folder(label = 'Default', user_id = user.id)
		db.session.add(default)
		db.session.commit()
		conns = Folder(label = 'Connections', user_id = user.id)
		db.session.add(conns)
		db.session.commit()
		login_user(user)
		flash("You've successfully registered.")
		return redirect(url_for('index'))
	return render_template('register.html', form = form)
Beispiel #18
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        return redirect(url_for('index'))
    return render_template('form.html', 
        title = 'Sign Up',
        form = form)
Beispiel #19
0
def register():
	error = None
	form = RegisterForm(request.form, csrf_enabled=False)
	if form.validate_on_submit():
		new_user = User(form.name.data,
						form.email.data,
						form.password.data, # again, why is there an extra comma in here
						)	# this makes my python sense tingle
Beispiel #20
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        u = um.add_user(form.name.data, form.password.data, form.email.data)
        mailing.send_awaiting_confirm_mail(u)
        flash(_('We have sent you confirm message, please check your Email~'))
        return redirect(url_for('home'))
    return render_template('register.html', form=form)
Beispiel #21
0
def register():
	form = RegisterForm()
	if form.validate_on_submit():
		user = User(form.username.data, form.password.data, form.name.data)
		db.session.add(user)
		db.session.commit()
		login_user(user)
		return redirect(url_for('core.index'))
	return render_template('login/register.html', form=form)
Beispiel #22
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(email=form.email.data, password=form.password.data)
        session.add(user)
        session.commit()
        login_user(user, remember=True)
        return redirect("/")
    return render_template("register.html", form=form)
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        data = add_user(form.data)
        send_registration_mail(data)
        return render('register_confirm.html', form=form)
    else:
        flash_errors(form)
    return render('register.html', form=form)
Beispiel #24
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, passwd=form.passwd.data)
        db.session.add(user)
        db.session.commit()
        flash('register success!')
        return redirect(url_for('main.index'))
    return render_template('auth/register.html', form=form)
Beispiel #25
0
def users(id = None):
	if g.user.admin:
		if request.method == 'DELETE' and id:
			db.session.delete(User.query.get(id))
			db.session.commit()
		form = RegisterForm()
		if request.method == 'GET' and id:
			user = User.query.get(int(id))
			if user.admin:
				role = 'Yes'
			else:
				role = 'No'
			form.username.data = user.username
			form.email.data = user.email
			form.admin.data = role
		if request.method == 'POST' and id and form.validate_on_submit():
			if form.admin.data == 'Yes':
				role = True
			elif form.admin.data == 'No':
				role = False
			user = User.query.get(int(id))
			user.username = form.username.data
			user.password = form.password.data
			user.email = form.email.data
			user.admin = role
			db.session.add(user)
			db.session.commit()
		if not id and form.validate_on_submit():
			if form.admin.data == 'Yes':
				role = True
			elif form.admin.data == 'No':
				role = False
			user = User(
			username = form.username.data,
			password = sha256(form.password.data).hexdigest(),
			email = form.email.data,
			admin = role,
			created = datetime.now())
			db.session.add(user)
			db.session.commit()
		alluser = User.query.all()
		return render_template('admin_users.html', form = form, alluser = alluser)
	else:
		return render_template('access_err.html')
Beispiel #26
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        newUser = User(nickname = form.username.data,
                password = form.password.data,
                email = form.email.data)
        db.session.add(newUser)
        db.session.commit()
        return redirect(url_for("thanks"))
    return render_template("register.html", title = "Register", form = form)
Beispiel #27
0
def register():
	form = RegisterForm(request.form)
	if form.validate_on_submit():
		reg = form.check_reg()
		if not reg:
			user = User(form.username.data, form.password.data)
			db.session.add(user)
			db.session.commit()
			return redirect(request.args.get("next") or url_for("login"))
	return render_template("register.html", form=form)
Beispiel #28
0
def register():
	error = None
	form = RegisterForm()
	if form.validate_on_submit():
		new_user = User(form.username.data, form.email.data, form.password.data)
		db.session.add(new_user)
		db.session.commit()
		flash("New user has been registered")
		return redirect(url_for("login"))
	return render_template('register.html', form=form, error=error)
Beispiel #29
0
def register():
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        user = User(email = form.email.data, username = form.username.data, password = generate_password_hash(form.password.data))
        db.session.add(user)
        db.session.commit()
        flask_login.login_user(user)
        flash('You are successfully register')    
        return redirect(url_for('home'))
    return render_template("register.html", form = form) 
Beispiel #30
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        models.User.create_user(
            name=form.name.data,
            email=form.email.data,
            password=form.password.data)
        flash('you registered', "success")
        return redirect(url_for('login'))
    return render_template('signup.html', form=form)
Beispiel #31
0
def edit_user(user_id):
    error = None
    new_id = user_id
    edit = db.session.query(User).filter_by(id=new_id)
    form = RegisterForm(request.form)

    for e in edit:
        form = RegisterForm(obj=e, )

    if request.method == 'GET':
        return render_template(
            'edit_user.html',
            form=form,
            error=error,
            username=session['name'],
            e=e,
        )

    if request.method == 'POST':
        if form.validate_on_submit():

            new_userobj = User.query.get(new_id)

            new_userobj.name = form.name.data
            new_userobj.email = form.email.data
            new_userobj.password = bcrypt.generate_password_hash(
                form.password.data)
            new_userobj.role = form.role.data

            try:
                db.session.commit()
                flash('The user was successfully updated.')
                return redirect(url_for('users.edit_accounts'))

            except IntegrityError:
                db.session.rollback()
                error = 'Sorry that username and/or email error already exist.'
                return render_template('edit_user.html',
                                       form=form,
                                       error=error,
                                       username=session['name'],
                                       e=e)
        else:
            return render_template('edit_user.html',
                                   form=form,
                                   error=error,
                                   username=session['name'],
                                   e=e)
Beispiel #32
0
def register():
    form = RegisterForm()
    if request.method == 'POST' and form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        firstname = form.firstname.data
        lastname = form.lastname.data
        gender = form.gender.data
        email = form.email.data
        location = form.location.data
        biography = form.biography.data
        photo = form.photo.data
        joined = format_date_joined(datetime.now())
        
        user = db.session.query(UserProfile).filter_by(user_name=username).first()
        eml = db.session.query(UserProfile).filter_by(email=email).first()
        
        if user is None and eml is None:
            filename = secure_filename(photo.filename)
            photo.save(os.path.join(
            app.config['UPLOAD_FOLDER'], filename
            ))
        
            #photoUrl = url_for('static', filename="uploads/" + filename)
            
            newuser = UserProfile(username,password,firstname,lastname,gender,email,location,biography,filename,joined)
            db.session.add(newuser)
            db.session.commit()
            
            er = None
            msg = "User Created Successfully"
            userData = {'id': newuser.id, 
            'email': newuser.email,
            'usernname': newuser.user_name, 
            'gender': newuser.gender, 
            'firstname': newuser.first_name, 
            'lastname': newuser.last_name, 
            'location': newuser.location, 
            'bio': newuser.biography, 
            'profile_pic': newuser.pic, 
            'joined': newuser.joined_on}
            
            return jsonify(error = er , data = {"newuser": userData}, message = msg),201
        else:
            msg = "Username and/or email already exist"
            return jsonify(error=[msg], message="Username and/or email already exist"),400
    else:
        return jsonify(errors = form_errors(form))
Beispiel #33
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        if User.query.filter_by(email=form.email.data).first():
            flash('You have already signed up with that Email! Login instead')
            return redirect(url_for("login"))
        new_user = User(
            email=form.email.data,
            password=generate_password_hash(form.name.data, method='pbkdf2:sha256', salt_length=8),
            name=form.name.data
        )
        db.session.add(new_user)
        db.session.commit()
        login_user(new_user)
        return redirect(url_for("get_all_posts"))
    return render_template("register.html", form=form, current_user=current_user)
Beispiel #34
0
def register():
    """
    Форма регистрации
    """
    form = RegisterForm()
    if form.validate_on_submit():
        # создать пользователя
        users = UsersModel(db.get_connection())
        if form.user_name.data in [u[1] for u in users.get_all()]:
            flash('Такой пользователь уже существует')
        else:
            users.insert(user_name=form.user_name.data, email=form.email.data, credit_card=form.card.data,
                         password_hash=generate_password_hash(form.password_hash.data))
            # редирект на главную страницу
            return redirect(url_for('index'))
    return render_template("register.html", title='Регистрация пользователя', form=form)
Beispiel #35
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        if User.query.filter_by(email=form["email"].data).first():
            flash("You've already registered with that email, login instead!!")
            return redirect(url_for("login"))
        new_user = User(email=form["email"].data,
                        password=generate_password_hash(form["password"].data,
                                                        method='pbkdf2:sha256',
                                                        salt_length=8),
                        name=form["name"].data)
        db.session.add(new_user)
        db.session.commit()
        login_user(new_user)
        return redirect(url_for("get_all_posts"))
    return render_template("register.html", form=form)
Beispiel #36
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        data = form.data
        user = User(
            name=data["name"],
            pwd=generate_password_hash(data["pwd"]),
            addtime=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        db.session.add(user)
        db.session.commit()
        # 定义一个会话闪现
        flash(u"注册成功,请登录", "ok")
        return redirect("/login/")
    else:
        flash(u"输入正确信息注册", "err")
    return render_template("register.html", title=u"注册", form=form)
def register_user():
    register_form = RegisterForm()
    if register_form.validate_on_submit():
        if register_form.password.data == register_form.c_password.data:
            new_user = User(permissions=register_form.tipo.data,
                            username=register_form.username.data,
                            password=register_form.password.data,
                            id_loja=register_form.loja_associada.data.id)
            db.session.add(new_user)
            db.session.commit()
            flash('Usuário %s criado com sucesso.' % new_user.username)
            return redirect(url_for('login'))
        else:
            flash('Senhas digitadas não estão iguais.')
            return redirect(url_for('register'))
    return render_template('register_pg.html', form=register_form)
Beispiel #38
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        password_hashed_and_salted = generate_password_hash(
            form.password.data, method='pbkdf2:sha256', salt_length=8)
        new_user = User(email=form.email.data,
                        password=password_hashed_and_salted,
                        name=form.name.data)

        db.session.add(new_user)
        db.session.commit()
        login_user(new_user)

        return redirect(url_for("get_all_posts"))

    return render_template("register.html", form=form)
Beispiel #39
0
def signup():
    form = RegisterForm()
    if form.password.data == form.password_confirm.data:
        if form.validate_on_submit():
            hashed_password = generate_password_hash(form.password.data,
                                                     method='sha256')
            new_user = User(username=form.username.data,
                            email=form.email.data,
                            password=hashed_password)
            db.session.add(new_user)
            db.session.commit()
            return '<h1>New User has been created</h1><br/><p><a href="JavaScript:history.go(-1);">Back</a></p>'
    else:
        return '<h1>Please ensure your passwords match!</h1><br/><p><a href="JavaScript:history.go(-1);">Back</a></p>'

    return render_template('register.html', form=form)
Beispiel #40
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = RegisterForm()
    if form.validate_on_submit():
        name = form.name.data
        username = form.username.data
        password = form.password.data
        user = User(name=name, username=username)
        user.set_password(password)
        db.session.add(user)
        db.session.commit()
        flash('Account created!', 'info')
        return redirect(url_for('login'))
    return render_template('auth/register.html', form=form)
Beispiel #41
0
def register():
    print("register")
    error = None
    form = RegisterForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            new_user = User(
                form.name.data,
                form.email.data,
                form.password.data,
            )
            db.session.add(new_user)
            db.session.commit()
            flash('Thanks for registering. Please login.')
            return redirect(url_for('login'))
    return render_template('register.html', form=form, error=error)
Beispiel #42
0
def register():
    form = RegisterForm()
    Role.insert_roles()
    if current_user.is_active():
        return redirect(url_for('landing_blueprint.index'))
    else:
        if form.validate_on_submit():
            user = User(username=request.form['username'],
                        email=request.form['email'],
                        password=request.form['password'],
                        role_id=3)
            db.session.add(user)
            db.session.commit()
            flash('Log In')
            return redirect(url_for('auth_blueprint.login'))
        return render_template('users/registration.html', form=form)
Beispiel #43
0
def password_changer():
    form = RegisterForm()
    if form.validate_on_submit():
        if form.special_password.data == str(g.user.password):
            if str(form.password.data) == str(form.double_password.data):
                db.session.delete(g.user)
                g.user.password = str(form.password.data)
                db.session.add(g.user)
                db.session.commit()
                flash('Changed successfully')
                return redirect(url_for('find'))
            else:
                flash("Passwords are not equal")
        else:
            flash("Wrong current password")
    return render_template('password_changer.html', form=form, user=g.user)
Beispiel #44
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        fcuser = Fcuser()
        fcuser.userid = form.data.get('userid')
        fcuser.username = form.data.get('username')
        fcuser.password = form.data.get('password')

        db.session.add(fcuser)
        db.session.commit()

        print('사용자등록 Success!')

        # redirct
        return redirect('/')
    return render_template('register.html', form=form)
Beispiel #45
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        email = form.email.data
        existing_user = User.query.filter_by(email=email).first()
        if existing_user:
            abort(400)
        first_name = form.first_name.data
        last_name = form.last_name.data
        user = User(email=email, first_name=first_name, last_name=last_name)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        login_user(user, remember=True)
        return redirect(url_for('homepage'))
    return render_template('register.html', form=form)
Beispiel #46
0
def register():
    form = RegisterForm()
    if request.method == "POST":
        if form.validate_on_submit():
            password = generate_password_hash(form.password.data,
                                              method='pbkdf2:sha256',
                                              salt_length=8)
            new_user = User(id=None,
                            email=form.email.data,
                            password=password,
                            name=form.name.data)
            db.session.add(new_user)
            db.session.commit()
            login_user(new_user)
            return redirect(url_for('get_all_posts'))
    return render_template('register.html', form=form)
Beispiel #47
0
def register():
    if current_user.is_authenticated:
        flash("Cant get to the register page. Already logged in")
        return redirect(url_for('home'))
    form = RegisterForm()
    if form.validate_on_submit():
        if User.query.filter_by(username=form.username.data).first():
            flash(f"{form.username.data} is already exist. try another username")
            return redirect(url_for('register'))
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        new_user = User(username=form.username.data, password=hashed_password, nation=form.nation.data)
        db.session.add(new_user)
        db.session.commit()
        flash(f"{form.username.data} has been registered succesfully, Wellcome to Avatar Quiz!")
        return redirect(url_for('login'))
    return render_template("register.j2", form=form, title="Register")
Beispiel #48
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        if db.session.query(User).filter_by(email=form.email.data).first():
            flash("User already exist! Please login into your account.")
            return redirect(url_for('login'))
        new_user = User(name=form.name.data,
                        email=form.email.data,
                        password=form.password.data)
        db.session.add(new_user)
        db.session.commit()
        login_user(new_user)
        return redirect(url_for('get_all_posts'))
    return render_template("register.html",
                           form=form,
                           current_user=current_user)
Beispiel #49
0
def register_form():
    form = RegisterForm()
    if not logged_in():
        if form.validate_on_submit():
            name, pas = form.login.data, form.password.data
            if not um.login_exists(name):
                um.add(login=name, password=pas)
                new_user = um.find(login=name, password=pas)[0]
                set_session(new_user['id'])
                return render_template('login_success.html',
                                       title='Registration successful')
            else:
                form.login.errors.insert(0, 'Имя уже занято')
        return render_template('register.html', title='Регистрация', form=form)
    else:
        return redirect(session.get('next', 'index'))
Beispiel #50
0
def register():
    if current_user.is_authenticated:
        flash('You are already registered')
        return redirect(url_for('todo'))

    reg_form = RegisterForm()
    if reg_form.validate_on_submit():
        user = User(email=reg_form.email.data,name=reg_form.name.data,
                 last_name=reg_form.last_name.data,password=reg_form.password.data,
                 date_added=datetime.now())
        db.session.add(user)
        db.session.commit()
        login_user(user)
        return redirect(url_for('todo'))

    return render_template('register.html', reg_form=reg_form)
Beispiel #51
0
def signup():
    form = RegisterForm()

    if form.validate_on_submit():
        hashed_password = generate_password_hash(form.password.data,
                                                 method='sha256')
        new_user = User(username=form.username.data,
                        email=form.email.data,
                        password=hashed_password)
        db.session.add(new_user)
        db.session.commit()

        return '<h1>New user has been created!</h1>'
        #return '<h1>' + form.username.data + ' ' + form.email.data + ' ' + form.password.data + '</h1>'

    return render_template('signup.html', form=form)
Beispiel #52
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None:
            user = User(
                email=form.email.data,
                username=form.username.data,
                password=form.password.data
            )
            db.session.add(user)
            db.session.commit()
            flash(u'注册成功')
            return redirect(url_for('hello_world'))
        flash('email has been registered')
    return render_template('register.html', form=form)
Beispiel #53
0
def signup():
    form = RegisterForm()

    if form.validate_on_submit():
        if form.email.data and form.username.data and form.password.data:
            hashed_password = generate_password_hash(form.password.data,
                                                     method='sha256')
            new_user = UserTable(username=form.username.data,
                                 email=form.email.data,
                                 password=hashed_password)
            db.session.add(new_user)
            db.session.commit()
            flash('You have successfully signed up')
            return render_template('index.html')

    return render_template('signup.html', form=form)
Beispiel #54
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        conn = get_db_connection()
        curs = conn.cursor()
        hashed = bcrypt.generate_password_hash(
            form.password1.data).decode('utf-8')
        curs.execute(
            "INSERT INTO users(email, name, surname, username, gender, password) VALUES (?, ?, ?, ?, ?, ?)",
            (form.email.data, form.name.data, form.surname.data,
             form.username.data, form.gender.data, hashed))

        conn.commit()
        conn.close()
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Beispiel #55
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(email=form.email.data, name=form.username.data)
        user.password = form.password.data
        user.save()
        print user.email
        token = user.generate_confirmation_token()
        send_email(user.email,
                   'Confirm Your Account',
                   'confirm',
                   user=user,
                   token=token)
        flash("A confirmation email has been sent to you by email.")
        return redirect(url_for("auth.login"))
    return render_template('auth/register.html', form=form)
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        password_hash = bcrypt.hashpw(
            request.form['password'].encode('utf-8'), bcrypt.gensalt())
        first_name = request.form['firstname']
        last_name = request.form['lastname']
        new_record = User(first_name, last_name, request.form['email'], password_hash)
        db.session.add(new_record)
        db.session.commit()
        session['user'] = first_name
        the_user = db.session.query(User).filter_by(email=request.form['email']).one()
        session['user_id'] = the_user.id

        return redirect(url_for('get_notes'))
    return render_template('register.html', form=form)
def register():
    form = RegisterForm()
    if request.method == 'POST' and form.validate_on_submit():
        h_password = bcrypt.hashpw(
            request.form['password'].encode('utf-8'), bcrypt.gensalt())
        first_name = request.form['firstname']
        last_name = request.form['lastname']
        new_user = User(first_name, last_name,
                        request.form['email'], h_password)
        db.session.add(new_user)
        db.session.commit()
        session['user'] = first_name
        session['user_id'] = new_user.id
        return redirect(url_for('index'))

    return render_template('register.html', form=form)
Beispiel #58
0
def register():
    error = None
    form = RegisterForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            new_user = User(form.name.data, form.email.data,
                            form.password.data)
            db.session.add(new_user)
            db.session.commit()
            flash('Thanks for Registering. please log in')
            return redirect(url_for('login'))
        else:
            flash_errors(form)
            return render_template('registration.html', form=form, error=error)
    if request.method == 'GET':
        return render_template('registration.html', form=form)
Beispiel #59
0
def register():
    error = None
    form = RegisterForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            new_user = User(form.name.data, form.email.data,
                            form.password.data)
            try:
                db.session.add(new_user)
                db.session.commit()
                flash('Thanks for registering. Please login.')
                return redirect(url_for('login'))
            except IntegrityError:
                error = 'That username and/or email already exist.'
                return render_template('register.html', form=form, error=error)
    return render_template('register.html', form=form, error=error)
Beispiel #60
0
def register():
    form = RegisterForm()
    # form 안에서 validate_on_submit을 통해서 post 요청이 되었고, 유효성 검사가 잘 되었는지 한번에 확인 가능
    # 값이 정상적인지, 모든 값들을 확인하는 코드모두 필요없어짐
    if form.validate_on_submit():
        student_info = Student()
        student_info.studentid = form.data.get('studentid')
        student_info.studentname = form.data.get('studentname')
        student_info.password = form.data.get('password')

        db.session.add(student_info) # db에 넣겠다! 라는 의미
        db.session.commit()
        print('Success')

        return redirect('/')
    return render_template('register.html', form=form)