Ejemplo n.º 1
0
def register():
    isSuccess=False
    isError=False
    success=""
    error=""
    if request.method == "POST":
        username = request.form['registerUsername']
        password = request.form['registerPassword']
        confirmPassword = request.form['confirmPassword']
        if username=="" or password=="" or confirmPassword=="":
            isError=True
            error="You forgot to fill out some required things..."
        elif database.check_username(username):
            if not password == confirmPassword: #passwords do not match
                isError=True
                error="Passwords do not match!"
            else:
                database.register_user(username,password)
                isSuccess=True
                success="Great! You have now successfully registered, "
                success=success+username
        else:
            #username is taken
            isError=True
            error="Sorry, your username is already in use!"
    return render_template("register.html", isError=isError, isSuccess=isSuccess, success=success, error=error)
Ejemplo n.º 2
0
 def __init__(self, user, first, last, expt):
     self.first = first
     self.last = last
     self.user = user
     self.experiment = expt
     if not database.user_data(self.user):
         database.register_user(self.user, self.get_id())
Ejemplo n.º 3
0
def test_register_user_exception():
    import database as db
    import datetime

    _test_user('exception_id')

    with pytest.raises(db.UserExists):
        db.register_user('exception_id')
Ejemplo n.º 4
0
def authenticate(email, password):
    exist = False
    users = db.select_users()
    for user in users:
        if ((user[1] == email) and (user[2] == password)):
            exist = True
    if (exist):
        print("User found, logging in...")
    else:
        print("User not found, registering...")
        db.register_user(email, password)
Ejemplo n.º 5
0
def test_register_user():
    import database as db
    import datetime

    _del_user('register_id')
    time = datetime.datetime.now()
    acceptable_timedelta = datetime.timedelta(seconds=10)

    db.register_user('register_id')

    out = db.User.objects.raw({'_id': 'register_id'}).first()
    assert (out.created - time) < acceptable_timedelta
Ejemplo n.º 6
0
    def register_request(self, message):
        """ Process an registration request for the client

        arguments:
            message: expected message is an array on the following format:
                ['Register request', Username, Password]
        """
        username = message[1]
        password = message[2]
        database.register_user(username, password)
        self.logger.info('New Username Registered: ' + username)
        self.send_text('Created')
def register_new_user(email: str, name: str):
    """
    Create a new user id and attempt a logon
    """

    # if has an at sign and at least one char each side, could be an email, accept it.
    if re.search('.+@.+', email) == None:
        # fails to match
        raise SantaErrors.SessionError("Not a valid email address.")

    # error if already registered
    check_user = database.get_registered_user(email)
    if len(check_user) > 0:
        raise SantaErrors.SessionError("Already registered.")

    database.register_user(email, name)
    return new_session(email)
Ejemplo n.º 8
0
def register():
    cnx = database.connect_sql()
    username = request.form.get('register_user')
    password = request.form.get('register_pass')
    register_status = database.register_user(cnx,
                                             username=username,
                                             password=password)
    cnx.close()
    return register_status
Ejemplo n.º 9
0
def signup():
    # signup page
    try:
        session["logged_in"]
    except KeyError:
        session["logged_in"] = False
    if not session["logged_in"]:
        if request.method == "GET":
            return render_template("signup.html", error=False)
        else:
            usr = request.form['username']
            pas = request.form['password']
            if username_exist(usr):
                return render_template("signup.html", error=True)
            else:
                register_user(usr, pas)
                return redirect(url_for("login"))
    else:
        return redirect(url_for("main"))
Ejemplo n.º 10
0
def registration():
    new_user = True
    if request.method == 'POST':
        user_name = request.form.get("user_name")
        password = request.form.get("password")
        hashed_password = data_handler.get_hashed_password(password)
        new_user = database.register_user(user_name, hashed_password)
        if new_user:
            session['username'] = user_name
            session['user_id'] = database.get_user_id(user_name)
            return redirect("/")
    return render_template("registration.html", new_user=new_user)
Ejemplo n.º 11
0
def UserRegister():
    first_name = request.form['first_name']
    last_name = request.form['last_name']
    email = request.form['email']
    password = request.form['password']
    address = request.form['address']
    pincode = request.form['pincode']
    phone_number = request.form['phone_number']
    if(db.register_user(first_name,last_name,email,password,address,pincode,phone_number)):
        return jsonify({"res":"success"}),200
    else:
        return jsonify({"res" : "fail"}),400
Ejemplo n.º 12
0
def register():
    data = request.get_json(silent=True)
    print('Received ', data.get('username'), ' and password.')

    register_user = db.register_user(data.get('username'),
                                     data.get('password'), 'none')

    if register_user == 'SUCCESS':
        print('User ', data.get('username'), ' registered!')
    else:
        print('Error registering user in database')
    return register_user
Ejemplo n.º 13
0
 def post(self, user_email, event_id):
     conn = database.open_connection(db_file)
     with conn:
         # Automatically register user in DB
         try:
             database.register_user(conn, user_email, event_id)
         except database.DuplicateError:
             # Ignore if duplicate
             pass
         try:
             database.register_event(conn, user_email, event_id)
             event = database.get_event(conn, event_id)
             email_utils.send_notification(smtp_context, user_email,
                                           event_id)
             email_utils.send_calendar_invite(
                 smtp_context, user_email, event)
         except database.NonExistingError:
             name_space.abort(400)
         except database.DuplicateError:
             # Ignore if duplicate
             pass
         return {}
     abort(500)
Ejemplo n.º 14
0
def handler_register_user():
    """
    Register a User on the database.
    """

    r = request.get_json()
    try:
        user_id = r['user_id']
        message = db.register_user(user_id)
        return jsonify(message), 200
    except ValidationError as e:
        return jsonify(e.message), 422
    except UserExists as e:
        out = "User exists."
        return jsonify(out), 200
    except KeyError as e:
        errormessage = 'Field {} is missing.'.format(e)
        return jsonify(errormessage), 400
Ejemplo n.º 15
0
def register_user():
	if 'session_username' in session:
		return redirect('/')
	registration_form = forms.RegistrationForm(request.form)
	if registration_form.validate_on_submit() and request.method == 'POST':
		user_name = request.form['user_name']
		if database.user_name_valid_for_registration(user_name):
			user_registration = database.register_user(request.form)
			if user_registration['registered']:
				session['session_username'] = user_name
				session['session_user_id'] = user_registration['user_id']
				return redirect('/')
			else:
				flash('Sorry, there seems to have been a problem with the database! Bad values, probably.')
				return redirect('/register_user')
				# flash good user name but db issue
		else:
			flash('Sorry, that user name is taken, try another!')
			return redirect('/register_user')
		# flash bad username message
		# should actually be done with ajax call that checks valid username as user inputs text
		# 
	# GET
	return render_template('register.html', form=registration_form)