Example #1
0
 def login():
     db = DatabaseConnection()
     user_input = request.get_json(force=True)
     username = user_input.get("user_name")
     password = user_input.get("user_password")
     validate = Validator.validate_user_login_credentials(
         username, password)
     if validate:
         return validate
     user = db.get_user(username)
     if user:
         verify_password = User_Controller.verify_hash(password, user[4])
         if verify_password:
             select = db.login_user(username, verify_password)
             if select:
                 expiry = datetime.timedelta(days=1)
                 user_data = {
                     "username": username,
                     "id": user[0],
                     "role": user[5]
                 }
                 access_token = create_access_token(identity=user_data,
                                                    expires_delta=expiry)
                 return jsonify({
                     'success':
                     f"You have successfully been logged in as {username}",
                     'access_token': access_token
                 }), 200
         return jsonify({'message': 'Incorrect user name or password'}), 400
     return jsonify({'message': f"{username} does not exist"}), 400
 def register_member():
     """Method to register a member"""
     db = DatabaseConnection()
     user_input = request.get_json(force=True)
     name = user_input.get("name")
     gender = user_input.get("gender")
     dateofbirth = user_input.get("dateofbirth")
     maritalstatus = user_input.get("maritalstatus")
     cell = user_input.get("cell")
     educationlevel = user_input.get("educationlevel")
     profession = user_input.get("profession")
     occupation = user_input.get("occupation")
     placeofwork = user_input.get("placeofwork")
     residence = user_input.get("residence")
     phonecontact = user_input.get("phonecontact")
     emailaddress = user_input.get("emailaddress")
     dateofbaptism = user_input.get("dateofbaptism")
     placeofbaptism = user_input.get("placeofbaptism")
     baptisingpastor = user_input.get("baptisingpastor")
     formerreligion = user_input.get("formerreligion")
  
     register_member = db.insert_member(name, gender, dateofbirth, maritalstatus,
                   cell, educationlevel, profession, occupation,
                   placeofwork, residence, phonecontact,
                   emailaddress, dateofbaptism, placeofbaptism,
                   baptisingpastor, formerreligion)
     return jsonify({'Success': "Member has been successfully registered"}), 201
Example #3
0
import re
from flask import jsonify, request
from passlib.hash import pbkdf2_sha256 as sha256
from app import app
from app.models.users_model import User
from app.controllers.db import DatabaseConnection
from app.validator import Validator
from flask_jwt_extended import (create_access_token, get_jwt_identity)
import datetime

db = DatabaseConnection()


class User_Controller:
    @staticmethod
    def verify_hash(password, hash):
        return sha256.verify(password, hash)

    @staticmethod
    def login():
        db = DatabaseConnection()
        user_input = request.get_json(force=True)
        username = user_input.get("user_name")
        password = user_input.get("user_password")
        validate = Validator.validate_user_login_credentials(
            username, password)
        if validate:
            return validate
        user = db.get_user(username)
        if user:
            verify_password = User_Controller.verify_hash(password, user[4])
Example #4
0
from app import app
from app.controllers.db import DatabaseConnection

db = DatabaseConnection()
db.setUp()

if __name__ == '__main__':
    app.run(debug=True)