def post(self): email = self.session.get(EMAIL_KEY) users = User.gql('WHERE email = :1', email) template_params={ } if (users.count(1) == 1): word = '' random = Random() for i in range(1,8): word += random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') user = users.get() user.password = word m = hashlib.md5() encodedString = word.encode('ascii', errors='replace') m.update(encodedString) user.passwordHash = str(m.hexdigest()) user.put() template_values = { "password":word } messageTemplate = jinja_environment.get_template('templates/userForms/changePassMail.html') message = mail.EmailMessage(sender="Diet Futar <*****@*****.**>") message.subject="Diet-futar, uj jelszo" message.to = email message.html = messageTemplate.render(template_values) message.send() template_params[EMAIL_KEY] = email template = jinja_environment.get_template('templates/userForms/changePassSuccess.html') self.printPage("Uj jelszo", template.render(template_params), True, True)
def post(self): #Check login email = self.request.get('email') password = self.request.get('password') m = hashlib.md5() encodedString = password.encode('ascii', errors='replace') m.update(encodedString) passwordHash = str(m.hexdigest()) users= User.gql('WHERE email = :1', email) if (users.count(1)==0): self.session[EMAIL_KEY]=email self.session[LOGIN_ERROR_KEY]="USER" self.redirect(clearNextPage(self)) elif (users[0].passwordHash != passwordHash): # self.session[EMAIL_KEY]=email self.session[LOGIN_ERROR_KEY] = "PASS" self.redirect(clearNextPage(self)) elif users[0].activated != True: self.session[EMAIL_KEY]=email self.session[LOGIN_ERROR_KEY] = "ACTIVATE" self.redirect(clearNextPage(self)) else: #Log the user in self.session[USER_KEY]=str(users[0].key()) self.redirect(clearNextPage(self))
def test_remove(self, cubmail): print "removing "+cubmail users = User.gql("WHERE cubmail = :1", cubmail) myclass = users.get() try: db.delete(myclass) except (Exception): print "can't find "+cubmail+"\n"
def _delete_all(self): for base in (Competition, UserComp, Scores, Comment): for item in base.query(): item.key.delete() for photo in Photo.query(): delete_blob(photo.blob) photo.key.delete() for user in User.gql('WHERE username != :1', 'test'): user.key.delete()
def get(self): email = self.session.get(EMAIL_KEY) users = User.gql('WHERE email = :1', email) template_params={ } if (users.count(1) == 1): template_params[EMAIL_KEY] = email template = jinja_environment.get_template('templates/userForms/changePass.html') self.printPage("Uj jelszo", template.render(template_params), True, True)
def IsUsernameAvailable(self,request): username = request.get("username") userid = request.get("userid") user = User.gql('WHERE username = :1',username).get() if user: if str(user.key()) == userid: return "True" else: return "Invalid" else: return "True"
def IsEmailAvailable(self,request): email = request.get("email") userid = request.get("userid") user = User.gql('WHERE email = :1',email).get() if user: if str(user.key()) == userid: return "True" else: return "Invalid" else: return "True"
def getSalt(email): print 'Content-Type: text/plain;charset=UTF-8' print '' logging.debug('email: ' + email) user = User.gql('WHERE email = :1', email).get() if user is not None: salt = user.password_salt else: #send back a dummy salt salt = User.generate_salt() print salt
def doLogin(args): user = None login_info = args.split(',',2) try: email_address = login_info[0] password_hash = login_info[1] user = User.gql('WHERE email_address = :1 AND password_hash = :2', email_address, password_hash).get() except IndexError: pass print 'Content-Type: text/plain;charset=UTF-8' print '' if user is None: print '0' else: Session().set_user(user) print '1'
def get(self): # Finds user with given email and activation code and activates it email = self.request.get('email') activationCode = self.request.get('activationCode') users = User.gql('WHERE email = :1', email) activationResult = -1 if (users.count(1) > 0): user = users[0] if (user.activationCode == activationCode): user.activated = True user.put() self.session[USER_KEY]=str(users[0].key()) activationResult = 0 else: activationResult = 2 else: activationResult = 1 template_values = { 'activationResult' : activationResult } template = jinja_environment.get_template('templates/userForms/activation/activation.html') self.printPage("Aktivacio", template.render(template_values), True)
def test_get_key(self, cubmail): result = User.gql("WHERE cubmail = :1", cubmail).get() return result.key()
def test_exists(self,cubmail): return User.gql("WHERE cubmail = :1", cubmail).get()
def post(self): referer = None refererKey = self.request.get('refererKey') if refererKey != None and refererKey != "": referer = User.get(refererKey) email = self.request.get('email') phoneNumber = self.request.get('phoneNumber') password = self.request.get('password') passwordCheck = self.request.get('passwordCheck') familyName= self.request.get('familyName') givenName= self.request.get('givenName') sourceOfInfo=self.request.get('sourceOfInfo') user = {} user["email"]= email user["familyName"]=familyName user["givenName"]=givenName user["phoneNumber"]=phoneNumber user["sourceOfInfo"]=sourceOfInfo users = User.gql('WHERE email = :1', email) refererUrlPart = "" if referer != None: refererUrlPart = "?refererKey=" + str(referer.key()) self.session[USER]=user if (users.count(1)>0): self.session[REGISTRATION_ERROR_KEY]=REGISTRATION_ERROR_EXISTING_USER self.redirect('/registration' + refererUrlPart) elif (passwordCheck != password): self.session[REGISTRATION_ERROR_KEY] = REGISTRATION_ERROR_PASSWORD_DOESNT_MATCH self.redirect('/registration' + refererUrlPart) elif familyName==None or familyName=="" or givenName==None or givenName=="": self.session[REGISTRATION_ERROR_KEY] = REGISTRATION_ERROR_USER_NAME_NOT_FILLED self.redirect('/registration' + refererUrlPart) else: #Everything went ok, create the user and log him in user = User() user.email = email user.familyName=familyName user.givenName=givenName user.password = "******" m = hashlib.md5() encodedString = password.encode('ascii', errors='replace') m.update(encodedString) user.passwordHash = str(m.hexdigest()) user.phoneNumber=phoneNumber user.activated = False user.registrationDate=datetime.datetime.now(timeZone) user.referer = referer user.sourceOfInfo = sourceOfInfo word = '' random = Random() for i in range(1,32): word += random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') user.activationCode = word user.put() updateUser(user) template_values = { 'email':email, 'activationCode':word, 'user':user } messageTemplate = jinja_environment.get_template('templates/userForms/activation/activation_code.html') message = mail.EmailMessage(sender="Diet Futar <*****@*****.**>") message.subject="Diet-futar, sikeres regisztracio" message.to = email message.body = messageTemplate.render(template_values) message.send() self.redirect("/activationPending")