Beispiel #1
0
def register():
    '''
    Handle user registrations.
    '''
    username_gotcha = 'The username <b>{0}</b> is taken!'.format
    password_gotcha = "The passwords you entered don't match."

    if request.method == 'POST':
        username = request.form.get('username').strip()
        password = request.form.get('password').strip()
        confirm = request.form.get('confirm').strip()
        phone = request.form.get('phone-number').strip()

        if user_exists(database, username):
            error = username_gotcha(username)
            return render_template('register.html', error=error, thanks=False)
        elif password != confirm:
            error = password_gotcha
            return render_template('register.html', error=error, thanks=False)

        else:
            register_user(database, username, password, phone)
            return render_template('register.html', error=None, thanks=True)

    return render_template('register.html', error=None, thanks=False)
Beispiel #2
0
def show_registration():
    user = utils.get_user_from_cookie(request)
    page_name = 'register'

    if request.method.lower() == 'get':
        page_content = render_template("register.html")
        return render_page(page_content, "register", user=user)

    if request.method.lower() == 'post':
        username = request.form.get("username") or ""
        password = request.form.get("password") or ""
        if not username or not password :
            page_content = render_template("register.html", message='Missing field')
            return render_page(page_content, page_name)

        if utils.check_username(username):
            page_content = render_template("register.html", message='That username is taken!')
            return render_page(page_content, page_name)

        seed = utils.generate_seed(username, request.remote_addr)
        totp_key = utils.get_totp_key(seed)
        utils.register_user(username, password, request.remote_addr)
        qr_url = 'http://api.qrserver.com/v1/create-qr-code/?data=otpauth://totp/%s?secret=%s&amp;size=220x220&amp;margin=0'%(username, totp_key)
        page_content = render_template(
            "register.html",
            message="Success! <a href='/login'>login here</a><br />TOTP Key: %s<br /><img src='%s' />" % (totp_key, qr_url)
        )

        return render_page(page_content, page_name)
Beispiel #3
0
def show_registration():
    user = utils.get_user_from_cookie(request)
    page_name = "register"

    if request.method.lower() == "get":
        page_content = render_template('register.html')
        return render_page(page_content, 'register', user=user)

    if request.method.lower() == "post":
        username = request.form.get('username') or ''
        password = request.form.get('password') or ''
        if not username or not password :
            page_content = render_template('register.html', message="Missing field")
            return render_page(page_content, page_name)

        if utils.check_username(username):
            page_content = render_template('register.html', message="That username is taken!")
            return render_page(page_content, page_name)

        seed = utils.generate_seed(username, request.remote_addr)
        totp_key = utils.get_totp_key(seed)
        utils.register_user(username, password, request.remote_addr)
        qr_url = "http://api.qrserver.com/v1/create-qr-code/?data=otpauth://totp/%s?secret=%s&size=220x220&margin=0"%(username, totp_key)
        page_content = render_template(
            'register.html',
            message='Success! <a href="/login">login here</a><br />TOTP Key: %s<br /><img src="%s" />' % (totp_key, qr_url)
        )

        return render_page(page_content, page_name)
Beispiel #4
0
def show_registration():
    user = utils.get_user_from_cookie(request)
    page_name = 'register'

    if request.method.lower() == 'get':
        page_content = render_template("register.html")
        return render_page(page_content, "register", user=user)

    if request.method.lower() == 'post':
        username = request.form.get("username") or ""
        password = request.form.get("password") or ""
        if not username or not password:
            page_content = render_template("register.html",
                                           message='Missing field')
            return render_page(page_content, page_name)

        if utils.check_username(username):
            page_content = render_template("register.html",
                                           message='That username is taken!')
            return render_page(page_content, page_name)

        seed = utils.generate_seed(username, request.remote_addr)
        totp_key = utils.get_totp_key(seed)
        utils.register_user(username, password, request.remote_addr)
        qr_url = 'http://api.qrserver.com/v1/create-qr-code/?data=otpauth://totp/%s?secret=%s&amp;size=220x220&amp;margin=0' % (
            username, totp_key)
        page_content = render_template(
            "register.html",
            message=
            "Success! <a href='/login'>login here</a><br />TOTP Key: %s<br /><img src='%s' />"
            % (totp_key, qr_url))

        return render_page(page_content, page_name)
Beispiel #5
0
def register():
    '''
    Handle user registrations.
    '''
    username_gotcha = 'The username <b>{0}</b> is taken!'.format
    password_gotcha = "The passwords you entered don't match."

    if request.method == 'POST':
        username = request.form.get('username').strip()
        password = request.form.get('password').strip()
        confirm = request.form.get('confirm').strip()
        phone = request.form.get('phone-number').strip()

        if user_exists(database, username):
            error = username_gotcha(username)
            return render_template('register.html', error=error, thanks=False)
        elif password != confirm:
            error = password_gotcha
            return render_template('register.html', error=error, thanks=False)

        else:
            register_user(database, username, password, phone)
            return render_template('register.html', error=None, thanks=True)

    return render_template('register.html', error=None, thanks=False)
 def test_add_and_view_buttons(self):
     register_user(self.browser)
     self.assertTrue(
         exists_by_xpath(self.browser, '//button[text()="Add"]')
     )
     self.assertTrue(
         exists_by_xpath(self.browser, '//a[text()="View expenses"]')
     )
     delete_user(self.browser)
Beispiel #7
0
def signup():
    if request.method == "POST":
        name = request.form['name']
        email = request.form["email"]
        pwd = request.form["pwd"]
        utils.register_user(name, email, pwd)
        return redirect(url_for("login"))
    else:
        return render_template("signup.html")
 def test_user_exists_error(self):
     register_user(self.browser)
     # Force Selenium to wait until the new user has been created.
     get_flashed_message(self.browser)
     register_user(self.browser, should_fail=True)
     message = get_flashed_message(self.browser)
     self.assertEqual(message, 'Username already exists.')
     # Delete. First user would have been created.
     delete_user(self.browser)
 def test_new_user_categories(self):
     register_user(self.browser)
     elem = wait_until(self.browser, '//select[@name="category_id"]')
     select = Select(elem)
     for option in select.options:
         if option.text == '(category)':
             self.assertTrue(option.text not in DEFAULT_CATEGORIES)
         else:
             self.assertTrue(option.text.lower() in DEFAULT_CATEGORIES)
     delete_user(self.browser)
Beispiel #10
0
def handle_registration():
    """Add new user to database and log user into site."""

    name = request.form.get('name')
    username = request.form.get('username')
    password = request.form.get('password')
    genres = request.form.getlist('genres')
    avatar = request.form.get('image_url')

    utils.register_user(name, username, password, genres, avatar)

    return redirect('/home')
Beispiel #11
0
def handle_registration():
    """Add new user to database and log user into site."""

    name = request.form.get('name')
    username = request.form.get('username')
    password = request.form.get('password')
    genres = request.form.getlist('genres')
    avatar = request.form.get('image_url')

    utils.register_user(name, username, password, genres, avatar)

    return redirect('/home')
Beispiel #12
0
def start(chat, message):
    kb = botogram.Buttons()
    kb[0].callback("📚 Apri il tuo libretto", "libretto")
    kb[1].callback("🔧 Impostazioni", "impostazioni")
    kb[1].callback("ℹ️ Informazioni", "informazioni")
    text = (
        "📝 <b>Benvenuto in iMarks!</b>\n\n"
        "In questo bot potrai salvare tutti i tuoi voti, calcolare i voti che"
        "ti servono per raggiungere le medie che desideri, e creare obiettivi"
        "e promemoria.\n\n"
        "<i>Seleziona un'opzione dal menu.</i>")
    chat.send(text, attach=kb)
    utils.register_user(message.sender.id)
def login():
    if request.method=="GET":
	return render_template("login.html")
    else:
	button=request.form['submit']
	print button
	if button=='Login':
            username = request.form['username']
	    password = request.form['password']
	    flash(utils.login_user(username, password))
	    return redirect("/")
	else:
	    username = request.form['username']
	    password = request.form['password']
	    print utils.register_user(username, password)
	    return redirect("/")
    def test_form_fields(self):
        register_user(self.browser)
        input_ = self.browser.find_element_by_xpath('//input[@name="cost"]')
        self.assertEqual(input_.get_attribute('placeholder'), 'Cost ($)')

        select = Select(
            self.browser.find_element_by_xpath('//select[@name="category_id"]')
        )
        self.assertEqual(select.first_selected_option.text, '(category)')

        input_ = self.browser.find_element_by_xpath('//input[@name="comment"]')
        self.assertEqual(input_.get_attribute('placeholder'), 'Comment')

        input_ = self.browser\
            .find_element_by_xpath('//input[@name="discretionary"]')
        self.assertEqual(input_.get_attribute('checked'), 'true')
        delete_user(self.browser)
Beispiel #15
0
 def setUp(self):
     url = '/auth/register'
     credentials = {
         'first_name': 'emre',
         'last_name': 'koc',
         'email': '*****@*****.**',
         'password': '******',
         'username': '******'
     }
     self.client = utils.register_user(self.client, url, credentials)
def register(new_user: UserCreateSchema, db: Session = Depends(get_db)):
    print(new_user.email)
    user = get_user_by_email(db=db, user_email=new_user.email)
    if user:
        raise HTTPException(status_code=400,
                            detail="User already registered, Please login.")
    else:
        try:
            register_user(db=db, user=new_user)
        except IntegrityError as err:
            raise HTTPException(status_code=400,
                                detail="Please Enter all required fields.")
        except ValidationError as err:
            raise HTTPException(status_code=400, detail=err)

        return {
            "message": "Successfully registered a new user",
            "data": new_user
        }
Beispiel #17
0
def register():
    if request.method == "GET":
        users = db.users.find()
        count = 0
        for u in users:
            if u['logged_in'] == True:
                count += 1
        return render_template("register.html", logged_in = count)
    else:
        if request.form["b"] == "Start Poopin'":
            message = validate(request.form, db)
            if message == 'Valid':
                register_user(request.form, db)
                flash('Account created')
                return redirect("login")
            else:
                return render_template("register.html", message = message)
        elif request.form["b"] == "Log In":
            return redirect("login")
        elif request.form["b"] == "About":
            return redirect("about")
        else:
            return render_template("register.html")
Beispiel #18
0
def register():
    if request.method == "GET":
        users = db.users.find()
        count = 0
        for u in users:
            if u['logged_in'] == True:
                count += 1
        return render_template("register.html", logged_in=count)
    else:
        if request.form["b"] == "Start Poopin'":
            message = validate(request.form, db)
            if message == 'Valid':
                register_user(request.form, db)
                flash('Account created')
                return redirect("login")
            else:
                return render_template("register.html", message=message)
        elif request.form["b"] == "Log In":
            return redirect("login")
        elif request.form["b"] == "About":
            return redirect("about")
        else:
            return render_template("register.html")
Beispiel #19
0
def register(user_type):
    base_url = "register_" + user_type + ".html"
    form = RegisterForm()
    if form.validate_on_submit():

        if user_exists(request.form['email'], user_type, db):
            flash("A user with this email already exists")
            return render_template(base_url, form=form, user_type=user_type)
        account = register_user(user_type, request.form, db)
        if account == "IV":
            flash("Invalid address. Make sure it looks like: 825 West End Ave #4A, New York.")
            return redirect("register/%s"%user_type)
        create_account(user_type, account, db)
        return redirect(url_for('login'))
    if request.method=="POST":
        flash("Your email or password is not valid. Please try again.")
    return render_template(base_url, form=form, user_type=user_type)
Beispiel #20
0
def register_test():
    if request.method == "POST":
        print(request.form)
        user_type = request.form["type"]
        print(user_type)
        form = RegisterForm()
        print(form)
        if form.validate_on_submit():
            print("HELLO")
            if user_exists(request.form['email'], user_type, db):
                flash("A user with this email already exists")
                return render_template("register_update.html")
        account = register_user(user_type, request.form, db)
        create_account(user_type, account, db)
        return redirect(url_for('login'))
    else:
        return render_template("register_update.html")
 def test_different_passwords_error(self):
     register_user(self.browser, password1='foo', password2='fo0',
                   should_fail=True)
     message = get_flashed_message(self.browser)
     self.assertEqual(message, 'Passwords do not match.')
 def setUp(self):
     self.browser = webdriver.Firefox()
     register_user(self.browser)
     login_user(self.browser)
 def setUp(self):
     self.browser = webdriver.Firefox()
     # register_use is tested explicitly in test_create_new_user.py
     register_user(self.browser)
 def setUp(self):
     self.browser = webdriver.Firefox()
     register_user(self.browser)
     self.browser.get('%s/account/settings' % SLATE_URL)
Beispiel #25
0
def register():
	username = get_form_value('username')
	password = get_form_value('password')
	password2 = get_form_value('password2')
	flash(utils.register_user(username, password, password2))
	return redirect(url_for('index'))
def register(user: schemas.forRegister):
    user_exists = utils.verify_user(user.email, user.password)
    if user_exists:
        raise HTTPException(status_code = 400, detail = 'User already registered')
    return utils.register_user(user)
 def test_success_message(self):
     register_user(self.browser)
     message = get_flashed_message(self.browser)
     self.assertEqual(message, 'Welcome to Slate!')
     delete_user(self.browser)
 def test_no_password_error(self):
     register_user(self.browser, password1='', password2='',
                   should_fail=True)
     message = get_flashed_message(self.browser)
     self.assertEqual(message, 'Password is required.')
 def test_alphanumeric_username(self):
     register_user(self.browser, username='******', should_fail=True)
     message = get_flashed_message(self.browser)
     self.assertEqual(message, 'Username must be alphanumeric.')