Ejemplo n.º 1
0
    def SessionLogout(self, jwt, url):
        """
        Sets the session as logged out and set the logoutDate.
        """
        if jwt is not None:
            currentUserSession = self.dbSession.query(
                UserSession).filter_by(jwToken=jwt).first()
            if currentUserSession is not None:
                if currentUserSession.loggedOut == False:
                    currentUserSession.loggedOut = True
                    currentUserSession.logoutDate = datetime.now()
                    currentUserSession.url = url
                    self.dbSession.commit()
                return DefaultMethodResult(True, 'Logout completed')

        return DefaultMethodResult(False, 'Error trying to logout')
Ejemplo n.º 2
0
    def register(self, username, email, password, mobilePhone) -> DefaultMethodResult:
        """
        This method will validate the data and create a new registration
        into our database.
        """
        error = self.validateRegisterData(username, password)

        # Converts the plain text password into a hash using the method 'generate_password_hash' from the 'werkzeug' library/package
        password = generate_password_hash(password)
        # If the error var still set as None, if is None proceed to the user creation
        # But if there is an error set, returns this error to the browser
        if error is None:
            newimage = App_User(username=username, email=email, password=password,
                           mobilePhone=mobilePhone)
            self.dbSession.add(newimage)
            self.dbSession.commit()
            return DefaultMethodResult(True, 'User Created')

        return DefaultMethodResult(False, error)
Ejemplo n.º 3
0
    def register(self, username, password, mobilePhone) -> DefaultMethodResult:
        """
        This method will validate the data and create a new registration
        into our database.
        """
        error = self.validateRegisterData(username, password)

        # Using a secured library (bcrypt) to hash the password with a generated salt
        password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
        # If the error var still set as None, if is None proceed to the user creation
        # But if there is an error set, returns this error to the browser
        if error is None:
            newUser = User(username=username,
                           password=password,
                           mobilePhone=mobilePhone)
            self.dbSession.add(newUser)
            self.dbSession.commit()
            return DefaultMethodResult(True, 'User Created')

        return DefaultMethodResult(False, error)
Ejemplo n.º 4
0
 def AddRequest(self, name, description, status, createdby,
                updated) -> DefaultMethodResult:
     createdat = datetime.now().isoformat()
     updatedat = createdat
     newrequest = Request(name=name,
                          description=description,
                          status=status,
                          createdby=createdby,
                          created_at=createdat,
                          updated_at=updatedat,
                          updated=updated)
     self.dbSession.add(newrequest)
     self.dbSession.commit()
     return DefaultMethodResult(True, 'Request added')
Ejemplo n.º 5
0
 def EditRequest(self, requestid, name, description, status, createdby,
                 updated) -> DefaultMethodResult:
     isupdated = updated
     # if updated.upper() == 'FALSE':
     #     isupdated = False
     # else:
     #     isupdated = True
     updatedat = datetime.now().isoformat()
     self.dbSession.query(Request).filter_by(requestid=requestid).update(
         {
             Request.name: name,
             Request.description: description,
             Request.status: status,
             Request.createdby: createdby,
             Request.updated_at: updatedat,
             Request.updated: isupdated
         },
         synchronize_session=False)
     self.dbSession.commit()
     return DefaultMethodResult(True, 'Request updated')
Ejemplo n.º 6
0
 def DeleteRequest(self, requestid) -> DefaultMethodResult:
     request = self.dbSession.query(Request).filter_by(
         requestid=requestid).first()
     self.dbSession.delete(request)
     self.dbSession.commit()
     return DefaultMethodResult(True, 'Request deleted')