Esempio n. 1
0
 def getUserByEmail(self, username):
     user = yield self.db.UserCollection.find_one(
         {User.PropertyNames.PrimaryEmail: username})
     if user:
         userprofile = User()
         userprofile.populate_data_dict(user)
         raise Return(userprofile)
Esempio n. 2
0
 def getUserByUserId(self, userId):
     userDict = yield self.db.UserCollection.find_one(
         {'_id': ObjectId(userId)})
     if userDict:
         user = User()
         user.populate_data_dict(userDict)
         raise Return(user)
Esempio n. 3
0
 def getUserByUserId(self, userId):
     if not isinstance(userId, uuid.UUID):
         userId = uuid.UUID(userId)
     userDict = yield self.db.UserCollection.find_one({'_id':userId})
     if userDict:
         user = User()
         user.populate_data_dict(userDict)
         raise Return(user)
Esempio n. 4
0
 def getUserByEmployeeId(self, employeeId):
     if not employeeId:
         raise NotImplementedError('employee ')
     user = yield self.db.UserCollection.find_one({User.PropertyNames.EmployeeId: employeeId})
     if user:
         userprofile = User()
         userprofile.populate_data_dict(user)
         raise Return(userprofile)
     raise Return(None)
Esempio n. 5
0
 def create_admin_user(self, postBodyDict):
     """
     :param postBodyDict:
     password
     email
     """
     user = User()
     user.Name = postBodyDict.get(user.PropertyNames.Name)
     user.Phone = postBodyDict.get(user.PropertyNames.Phone)
     user.PrimaryEmail = postBodyDict.get(RegisterRequestParams.Email)
     # employee_exists = False
     # if postBodyDict.get(user.PropertyNames.EmployeeId):
     #     user.EmployeeId = postBodyDict.get(user.PropertyNames.EmployeeId)
     # (employee_exists, _) = yield self.check_if_user_exists_with_same_employee_id(user.EmployeeId)
     (user_exists, _) = yield self.check_if_user_exists_with_same_email(
         user.PrimaryEmail)
     if user_exists:
         raise Return((False, 'User already exists'))
     password = yield self.get_hashed_password(
         postBodyDict.get(RegisterRequestParams.Password))
     linkedaccount = LinkedAccount()
     user.UserId = uuid.uuid4()
     linkedaccount.AccountName = user.PrimaryEmail
     linkedaccount.AccountHash = password.get('hash')
     linkedaccount.AccountType = LinkedAccountType.Native
     user.LinkedAccounts = [linkedaccount]
     user.Status = UserStatus.Registered
     user.EmailValidated = EmailValidationStatus.NotValidated
     user_result = yield self._uh.save_user(user.datadict)
     # user = yield self._uh.getUserByUserId(user_result.inserted_id)
     # group = yield self._gh.createDummyGroupForUser(user_result.inserted_id)
     # yield self._gh.createGroupMemberMappingForDummyGroup(group.inserted_id, user_result.inserted_id)
     raise Return((True, user))
Esempio n. 6
0
 def create_invited_state_user(self, invitedDict):
     employee=User()
     employee.Name = invitedDict.get(CreateEmployeeRequestParams.Name)
     employee.PrimaryEmail = invitedDict.get(CreateEmployeeRequestParams.EmailId)
     employee.UserId = uuid.uuid4()
     employee.Status=UserStatus.Invited
     employee.EmailValidated=False
     employee.CreatedTimeStamp=datetime.datetime.now()
     employee.UpdatedTimeStamp=datetime.datetime.now()
     return employee
Esempio n. 7
0
 def create_invited_state_user(self, invitedDict, groupId):
     employee = User()
     employee.Name = invitedDict.get(CreateEmployeeRequestParams.Name)
     employee.Phone = invitedDict.get(CreateEmployeeRequestParams.Phone)
     employee.UserId = uuid.uuid4()
     account = LinkedAccount()
     password = yield self.get_hashed_password(invitedDict.get(CreateEmployeeRequestParams.Password))
     account.AccountName = employee.Phone
     account.AccountHash = password.get('hash')
     account.AccountType = LinkedAccountType.Native
     employee.Status = UserStatus.Invited
     employee.EmailValidated = False
     employee.CreatedTimeStamp = datetime.datetime.now()
     employee.UpdatedTimeStamp = datetime.datetime.now()
     yield self._uh.save_user(employee.datadict)
     raise Return(employee)
Esempio n. 8
0
from api.stores.user import User

if __name__ == "__main__":
    user = User()
    user.primary_email = 'me'
    user.companyname = 'me'
    user.LinkedAccounts.accountname = 'me'
    user.LinkedAccounts.accounthash = 'me'
    user.populate_data_dict()
    print(user.data_dict)