Пример #1
0
 def regitserOwner(self,email,password=None,screenname=None):
      
      isEmailAvailable = False
      resp = {}
      socialPassword = '******'
      
      for owner in Owners.objects(email=email):
           isEmailAvailable = True
           ownerid = str(owner.id)
           token = authentication.generateToken(ownerid)
           ownerpassword = owner.password
           resp['ownerid'] = ownerid
           resp['screenname'] =  owner.screenName
           resp['registerstatus'] =  owner.registerStatus
           resp['token'] =  token
           resp['stats'] = owner.stats
           break
      
      if (isEmailAvailable == True and password != None):
           if checkPassword(ownerpassword,password) == False:
                resp = {'error':'Invalid password'}
                   
      
      if (isEmailAvailable == False and screenname == None):
           if (password == None):
                resp = {'error':'socialscreenname'}
           else:
                resp = {'error':'Need a screen name.'}
           
      elif (isEmailAvailable == False):
           owner = Owners()
           owner.email = email
           owner.screenName = screenname.lower()
           owner.registerStatus = "AWAITING"
           owner.favorites = []
           owner.followers = []
           owner.stats = {'mailCount' : 1}
           owner.pins = {}
           if password == None:
                owner.password = socialPassword
           else:
                owner.password = hashPassword(password)
           owner.creationDate = datetime.now()
           owner.lastModifiedDate = datetime.now()
           try:
                data = owner.save()
                resp['ownerid'] =  str(data.id)
                token = authentication.generateToken(str(data.id))
                resp['screenname'] =  owner.screenName
                resp['registerstatus'] =  owner.registerStatus
                resp['token'] =  token
                resp['stats'] = owner.stats
                self.__sendWelcomeMail(email,resp['screenname'])
           except Exception, e:
                if 'duplicate' in str(e):
                     resp = {"error" : "Screen Name Already Exists"}
                else:
                     self.logger.error('registerOwner_Exception')
                     self.logger.error(str(e),exc_info=True)
                     resp = {"error" : "Unknown Error"}
Пример #2
0
 def updatePassword(self,ownerid,oldpassword,newpassword):
      
      resp = {}
      existingPassword = None
      owner = None
      
      for o in Owners.objects(id=ownerid):
           existingPassword = o.password
           owner = o
      
      if owner == None:
           resp = {"error" : "Given owner not found"}
      else:
           if checkPassword(existingPassword,oldpassword) == False:
                resp = {"error" : "Wrong old password"}
           else:
                owner.password = hashPassword(newpassword)
                owner.save()
                resp = {"success" : "OK"}
                
      return {"data" : resp}