def get(self): user = users.get_current_user() user_id = user.user_id() email = user.email() if user: myUser = User.all().filter('id = ',user_id) if(myUser.count() >= 1): userMetaData = json.loads(myUser[0].metadata) if (userMetaData['profile_completed'] == 0): path = os.path.join(os.path.dirname(__file__), '../views' , 'complete_profile.html') self.response.out.write(template.render(path,locals())) else: self.redirect('/home') else: userDict ={} userDict['is_first_time'] = 1; userDict['profile_completed'] = 0; new_user = User() new_user.id = user_id new_user.email = email; new_user.metadata = json.dumps(userDict) new_user.put() path = os.path.join(os.path.dirname(__file__), '../views' , 'complete_profile.html') self.response.out.write( template.render(path,locals()) ) else: self.redirect('/login')
def create(self): try: createParams = { "fields" : { "email": { "type": "string", "required": True, "regex": '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$' }, "password": {"type": "string","required": True,"minlength":4} }, "message" : { "email":{ "type": "тэмдэгт оруулна уу", "required": "email тодорхойгүй байна", "regex": "имэйлээ зөв оруулна уу" }, "password":{ "type": "Нууц үг үсэг тоо байна", "required": "Нууц үг тодорхойгүй байна", "minlength": "Нууц үг 4 олон тэмдэгттэй байна" } } } v = BuValidator(createParams) v.validate(request.json) code = '123456' password_hashed = bcrypt.hashpw(request.json['password'].encode("utf8"), bcrypt.gensalt()) code_hashed = bcrypt.hashpw(code.encode("utf8"), bcrypt.gensalt()) user = User( uuid=User.generateID(), email=request.json['email'], password = password_hashed, activation = code_hashed ) session.add(user) session.flush() return json.dumps({ 'result':'success' }) except Exception as e: msg = e.args if len(e.args)>0 else str(e) return json.dumps({ 'result':'error', 'msg': msg },ensure_ascii=False).encode('utf8')
def getUserbyId(user_id): if not user_id: return False; myUser = User.all().filter('id = ',user_id) if(myUser): return myUser[0] else: return False
def register_service(): name = request.params.name surname = request.params.surname user_email = request.params.user_email password = request.params.password user = User.create(email=user_email, password=password, first_name=name, last_name=surname) auth.add_membership('member', user) isRegister = False if user.id > 0: isRegister = True db.commit() data = [{'success': isRegister}] return dict(data=data)
def post(self): current_user = users.get_current_user() if(not current_user): self.redirect('/login') else: user_id = current_user.user_id() nickname = self.request.get('nickname') aboutme = self.request.get('about-me') allusers = User.all().filter('id = ',user_id) for user in allusers: if(user): userMetaData = json.loads(user.metadata) if(userMetaData['is_first_time']): userMetaData['profile_completed'] = 1 userMetaData['is_first_time'] = 0 user.nickname = nickname user.aboutme = aboutme user.metadata = json.dumps(userMetaData) user.put() self.redirect('/home') else: self.redirect('/home') else: self.response.out.write("Sorry something went wrong, Please try again")