Example #1
0
def register():
    if request.method=="GET":
        return render_template("register.html")
    elif request.method=="POST":
        user_name=request.form["username"]
        password=request.form["password"]
        user=User(user_name,password,time.strftime("%Y-%m-%d %T"),None)
        User.add(user)
        session["user"]=serials.getDict(user)
        return redirect(url_for("vip.index"))
Example #2
0
def create_user():
    """Attempts to creates a new user in the DB from the passed in POST request data
    Redirects to the all users list if successful """
    f_name = request.form['first_name']
    l_name = request.form['last_name']
    image = request.form['image_url']
    # first name is required
    if f_name == '':
        flash('You must enter a First Name')
        return redirect('/users/new')
    else:
        User.add(f_name, l_name, image)
        return redirect('/users')
Example #3
0
def signup():

    if request.method == 'POST' and request.headers[
            'Content-Type'] == 'application/json':

        data = request.get_json()
        if not data:
            obj = {"status": cmn.ERROR_VALUE, "message": cmn.getErr("E000001")}
            return jsonify(obj)

        check_obj = checkUserData(data, 0)
        if check_obj['status'] == 0:
            return jsonify(check_obj)

        save_data = {
            'username':
            data['username'].strip(),
            'email':
            data['email'].strip(),
            'password':
            bcrypt.generate_password_hash(
                data['password'].strip()).decode('utf-8')
        }

        # check email is unique.
        pe = "user_id"
        fe = "email = :email"
        search_obj = {":email": data['email']}
        user_list = User.findItem(pe, fe, search_obj)
        if isinstance(user_list, list):
            if len(user_list) != 0:
                obj = {
                    "status": cmn.ERROR_VALUE,
                    "message": cmn.getErr("E120001")
                }
                return jsonify(obj)
        else:
            obj = {"status": cmn.ERROR_VALUE, "message": cmn.getErr("E000002")}
            return jsonify(obj)

        # save user data.
        user = User(save_data['username'], save_data['email'],
                    save_data['password'])
        save_user = user.getObj()
        res = User.add(save_user)

        obj = {}
        if res['ResponseMetadata']['HTTPStatusCode'] == 200:
            obj = {"status": cmn.SUCCESS_VALUE}
        else:
            obj = {"status": cmn.ERROR_VALUE, "message": cmn.getErr("E000002")}

        return jsonify(obj)
Example #4
0
def getNewUser(request):
    newUser = User()
    newUser.add('name', request.form['name'])
    newUser.add('email', request.form['email'])
    newUser.add('username', request.form['username'])
    newUser.add('password', request.form['password'])
    newUser.add('bookLimit', CHECKOUT_LIMIT)
    newUser.add('booksCheckedOut', [])
    newUser.add('isAdmin', False)
    newUser.add('isRedFlagged', False)
    return newUser