def register(): """ Validates the request body and tries to register the user """ body = validate( { "username": field("string", maxlength=180, required=True, empty=False, nullable=False), "email": field("email"), "password": field("password"), "tos": field("tos") }, request.get_json(force=True, silent=True)) if not body["tos"]: raise CustomError( message="Servis kosullarini kabul etmeniz gerekmektedir", status_code=400) user = User(body) user.registration_ip = request.access_route user_register(user) return "User successfully registered."
def searchUser(self,username): sql = 'select user_no, name from m_user where name = %s' user = Connector().selectOne(sql, (username,)) if not user: return None else: return User(user['user_no'],user['name'])
def loginUser(self,username,password): sql = 'select user_no, name from m_user where name = %s and password = %s' user = Connector().selectOne(sql, (username, hashlib.sha256(password.encode('utf-8')).hexdigest())) if not user: return None else: return User(user['user_no'],user['name'])
def register(user: User): """ Tries to insert a new user to the database, send verification mail to him """ try: user.ts_registration = time() user.ts_last_login = time() user.enabled = True user.email_verified = False user.roles = [Roles.ROLE_USER] user.password = encrypt(user.password) insert(user) except IntegrityError as e: raise CustomError( message="Bu e-mail veya kullanici adi ile zaten bir kullanici var", status_code=400, ) current_app.logger.debug('User with email {} registered'.format( user.email)) send_verification_email( user.email, encode(user.jwt_payload(), current_app.config["JWT_SECRET"], current_app.config["JWT_TTL"]))
def validate_payload_for_creation_and_hydrate(self): values = [] values.append(None) for api_field, data in User.expected_fields.items(): value = JsonHelper.get_value_from_request(api_field, None) if value is None: if data['required'] is True: raise MissingFieldException(api_field) values.append(data['default']) else: values.append(value) values.append(None) values.append(None) user = User(*values) # pylint: disable=E1120 check_user = self.user_repository.get_by_email(user.get_email()) if check_user is not None: raise ResourceAlreadyExistsException('user', user.get_email(), 'email') check_user = self.user_repository.get_by_user_name( user.get_user_name()) if check_user is not None: raise ResourceAlreadyExistsException('user', user.get_user_name(), 'username') return user
def register(): """ Validates the request body and tries to register the user """ body = validate( { "fullname": field("string", maxlength=100), "email": field("email"), "password": field("password"), "tos": field("tos") }, request.get_json(force=True, silent=True)) if not body["tos"]: raise CustomError(message="ToS is not accepted.", status_code=400) user = User(body) user.registration_ip = request.access_route user_register(user) return "User successfully registered."
def hydrate(self, row): """Hydrate an object from a row.""" user = User( row['id'], row['email'], row['password'], row['status'], row['user_name'], row['salt'], row['token'], ) return user
def find_by_id(user_id: int) -> Union[User, None]: """ Returns the user given id """ get_db() g.cursor.execute("SELECT * FROM user WHERE id = %s", [user_id]) row = g.cursor.fetchone() close_db() if row is None: return None return User(row)
def find_by_email(email: str) -> Union[User, None]: """ Returns the user given email """ get_db() g.cursor.execute("SELECT * FROM user WHERE email = %s", [email]) row = g.cursor.fetchone() close_db() if row is None: return None return User(row)
def register(user: User): """ Tries to insert a new user to the database, send verification mail to him """ try: user.ts_registration = time() user.ts_last_login = time() user.enabled = True user.email_verified = False user.roles = [Roles.ROLE_USER] user.password = encrypt(user.password) insert(user) except IntegrityError as e: raise CustomError( message="User already registered", status_code=400, ) current_app.logger.debug('User with email {} registered'.format( user.email))