Exemple #1
0
    def get(self, id):
        if not self.id_valid(id):
            return {'message': 'User not found', 'data': {}}, 404

        user_result = get_user(id)
        user = User(user_result)

        return {'message': 'User', 'data': user.serialize()}, 200
Exemple #2
0
    def get(self):
        user_result = get_users()

        users = []

        for res in user_result:
            users.append(User(res).serialize())

        return {'message': 'Success', 'data': users}, 200
Exemple #3
0
    def createAccount(self):
        userName=self.loginEntry.get()
        password=self.passwordEntry.get()
        user=User(userName, password)
        try:
            if(UserController().saveUserToDatabase(user)):
                messagebox.showinfo("Message", "ACCOUNT CREATED")
            else:
                messagebox.showinfo("ERROR", "LOGIN ALREADY TAKEN")

        except:
            messagebox.showinfo("ERROR","IDK ERR")
 def findUser(self, username):
     sql = "SELECT * FROM USERS WHERE NAME = '%s'" % (username)
     self.cursor.execute(sql)
     result = self.cursor.fetchall()
     from models.UserModel import User
     user = None
     for row in result:
         name = row[1]
         password = row[2]
         charge = row[3]
         user = User(name, password)
         user.charge = charge
     return user
 def findAllUsers(self):
     users = []
     sql = "SELECT * FROM USERS"
     self.cursor.execute(sql)
     results = self.cursor.fetchall()
     for row in results:
         name = row[1]
         password = row[2]
         charge = row[3]
         from models.UserModel import User
         user = User(name, password)
         user.addCharge(charge)
         users.append(user)
     return users
Exemple #6
0
    def put(self, user_id, title):
        if not self.id_valid(user_id):
            return {'message': 'User not found', 'data': {}}, 404

        user_result = get_user(user_id)
        user = User(user_result)

        parser = reqparse.RequestParser()

        parser.add_argument('title', required=True)
        parser.add_argument('comment', required=True)

        # Parser arguments into obj
        args = parser.parse_args()

        note = {
            'title': args['title'] + "*" + str(user_id),
            'author': f'{user.first_name} {user.last_name}',
            'comment': args['comment'],
            'expiration': '2020-12-02'
        }

        updated = PauliusNoteService().update_note(title + "*" + str(user_id),
                                                   note)

        if updated is None:
            return {
                'message': 'Unknown error occurred try again later',
                'data': args
            }, 500

        if updated == 202:
            new_title = args['title'] + "*" + str(user_id)
            old_title = title + "*" + str(user_id)
            update_user_note(old_title, new_title)
            return {'message': 'Success', 'data': args}, 200
        if updated == 409:
            return {
                'message': 'A note with this title already exists',
                'data': args
            }, 404
        if updated == 404:
            return {'message': 'Note not found', 'data': {}}, 404
Exemple #7
0
def register():

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

        # check if user with the email exists in the database
        user_exists = User.query.filter_by(email = email).first()
        if user_exists:
            return jsonify({'message': 'user email already exists'}), 404

        user = User(email, password, '', '', datetime.timestamp(datetime.now()), datetime.timestamp(datetime.now()))
        user.hash_password(password)
        db.session.add(user)
        db.session.commit()

        access_token = create_access_token(identity=user.id, fresh=True)
        refresh_token = create_refresh_token(user.id)

        return jsonify({'access_token': access_token, 'refresh_token': refresh_token}), 200
Exemple #8
0
def registerUser():
    try:
        user = User(
            **{a: request.json[a]
               for a in User.attributes() if a != 'id'})

        # Checking if user already exists
        v.validateUser(User, user.email)

        # Hashing the password
        user.password = pbkdf2_sha256.hash(user.password)

        db.session.add(user)
        db.session.commit()

        return jsonify({'status': 'success'}, {
            'message':
            f'Thanks for using Products API, {user.firstName}.Now you\'re registered and can log in'
        }), 201
    except Exception as e:
        return jsonify({'status': 'fail'}, {'message': str(e)}), 404
Exemple #9
0
    def get(self, user_id):
        if not self.id_valid(user_id):
            return {'message': 'User not found', 'data': {}}, 404

        notes = PauliusNoteService().get_all_notes()

        user_result = get_user(user_id)
        user = User(user_result)

        user_notes_results = get_user_notes(user_id)
        user_notes = []

        for note in notes:
            for res in user_notes_results:
                if note.title == res[2]:
                    user_notes.append(note)

        return {
            'message': 'User notes',
            'data': UserNotes(user, user_notes).serialize()
        }, 200
    def get(self):
        user_result = get_users()

        users = [User(res) for res in user_result]
        notes = PauliusNoteService().get_all_notes()
        users_notes = []

        for user in users:
            note_results = get_user_notes(user.id)

            # if  paulius note title matches with user note table title, then add it to user_notes
            user_notes = []

            for note in notes:
                for res in note_results:
                    if note.title == res[2]:
                        user_notes.append(note)

            users_notes.append(UserNotes(user, user_notes).serialize())

        return {'message': 'Success', 'data': users_notes}, 200
Exemple #11
0
 def do_regis(request):
     tel = request.form.get("telephone")
     un = request.form.get("username")
     pwd1 = request.form.get("password1")
     pwd2 = request.form.get("password2")
     if tel and un and pwd1 and pwd2:
         if User.query.filter_by(telephone=tel).first():
             return "exit"
         else:
             if pwd1 == pwd2:
                 user = User(telephone=tel, username=un, password=pwd1)
                 try:
                     db.session.add(user)
                     db.session.commit()
                     return "ok"
                 except Exception as e:
                     print(e)
                     db.session.rollback()
                     return "fall"
             else:
                 return "ns"
     else:
         return "nf"