def getUserById(self, usrid):
     dao = UsersDAO()
     result = dao.getUserById(usrid)
     if result:
         user = self.arrange(result)
         return jsonify(User=user)
     return jsonify(ERROR='User doesn\'t exists')
 def getUsersEmails(self):
     dao = UsersDAO()
     result = dao.getUsersEmails()
     users = []
     for r in result:
         users.append(self.arrange2(r))
     return jsonify(Users=users)
 def getUsersByUsername(self, username):
     dao = UsersDAO()
     result = dao.getUsersByName(username)
     if result:
         user = self.arrange(result)
         return jsonify(Users=user)
     return jsonify(ERROR="User doesn\'t exists")
 def getUsers(self):
     dao = UsersDAO()
     result = dao.getUsers()
     users = []
     for i in result:
         users.append(self.arrange(i))
     return jsonify(Users=users)
 def getUserByPhone(self, phone):
     dao = UsersDAO()
     result = dao.getUserByPhone(phone)
     mapp = []
     for r in result:
         mapp.append(self.arrangePhone(r))
     return jsonify(Phone=mapp)
 def authorize(self, form):
     if len(form) != 2:
         return jsonify(ERROR='Malformed request formed(first if)')
     else:
         username = form['username']
         password = form['password']
         if username and password:
             dao = UsersDAO()
             auth = dao.authorize(username, password)
             if auth:
                 result = self.arrange(auth)
                 return jsonify(User=result)
             else:
                 return jsonify(ERROR='Wrong Password or Username/Email')
         else:
             return jsonify(ERROR='Malformed request form(last return)')
 def insertUser(self, form):
     if len(form) != 6:
         return jsonify(ERROR="Malformed form"), 401
     else:
         fname = form['firstname']
         lname = form['lastname']
         phone = form['phone']
         email = form['email']
         username = form['username']
         password = form['password']
         if fname and lname and phone and email and username and password:
             dao = UsersDAO()
             exists = dao.check(username)
             print(exists)
             if exists:
                 new = dao.insert(fname, lname, phone, email, username,
                                  password)
                 result = self.arrangeID(new)
                 return jsonify(User=result)
             else:
                 return jsonify(ERROR='Username already exists')
         else:
             return jsonify(ERROR='After method')