예제 #1
0
    def post(self):
        # post a user using valid credentials
        try:
            data = api.payload

            email = data['email']
            password = data['password']

            # checks if the email exists
            if UserModel.check_email_exist(email):
                # checks if the password is valid
                if UserModel.check_password(email, password):
                    return {'status': 'User successfully logged in'}, 200
                else:
                    return {'status': 'Wrong login credentials!'}, 401
            else:
                return {'status': 'Email does not exist!'}, 401
        except KeyError as e:
            api.abort(500,
                      e.__doc__,
                      status="Could not perform this action",
                      statusCode="500")
        except KeyError as e:
            api.abort(400,
                      e.__doc__,
                      status="Could not perform this action",
                      statusCode="400")
예제 #2
0
    def post(self):
        try:
            data = api.payload

            username = data['username']
            email = data['email']
            password = data['password']

            if UserModel.check_email_exist(email):
                return {"status": "Email already exists"}, 400
            else:

                hashed_password = generate_password_hash(password)

                user = UserModel(username=username,
                                 email=email,
                                 password=hashed_password)
                user.create_record()

                return {"status": "User added successfully"}, 201
        except KeyError as e:
            api.abort(500,
                      e.__doc__,
                      status="Could not perform this action",
                      statusCode="500")
        except KeyError as e:
            api.abort(400,
                      e.__doc__,
                      status="Could not perform this action",
                      statusCode="400")
예제 #3
0
    def post(self):
        data = api.payload

        email = data['email']
        password = data['password']

        if UserModel.check_email_exist(email):
            
            if UserModel.check_password(email,password):

                return {"message":"Successfully logged in"}
            else:
                return {"message":"Wrong login credentials!"}
        else:
            return {"message":"Email does not exist!"}
예제 #4
0
def login():

    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        # Check if email exists
        if UserModel.check_email_exist(email):
            # Check if the password is valid
            if UserModel.check_password(email, password):
                session['logged_in'] = True
                session['username'] = UserModel.fetch_by_email(email).username
                session['id'] = UserModel.fetch_by_email(email).id
                return redirect(url_for('home'))
            else:
                flash('Wrong login credentials!   Please Try Again!!',
                      'danger')
                return redirect(url_for('login'))
        else:
            flash('Email does not exist', 'danger')
    return render_template('login.html')
예제 #5
0
def register():

    # Fetch all inputs from users
    if request.method == 'POST':
        username = request.form['username']
        email = request.form['email']
        password = request.form['password']

        if UserModel.check_email_exist(email):
            flash('Email already exists', 'danger')
            return redirect(url_for('register'))
        else:
            hashed_password = bcrypt.generate_password_hash(password).decode(
                'utf-8')

            user = UserModel(username=username,
                             email=email,
                             password=hashed_password)
            user.create_task()
            flash('User Successfully Added', 'success')
            return redirect(url_for('login'))

    return render_template('register.html')