def register(self, username, password, email, sex): check_user(username) self.__check_password(password) self.__check_email__(email) user_profile = UserProfile(username=username, email=email, sex_str=sex) user_profile.set_password(password) user_profile.save() RoomUsers(user_id=user_profile.id, room_id=settings.ALL_ROOM_ID, notifications=False).save() if email: yield from self.__send_sign_up_email(user_profile) return MessagesCreator.get_session( self.__generate_session__(user_profile.id))
def auth(self, username, password): """ Logs in into system. """ try: if '@' in username: user = UserProfile.objects.get(email=username) else: user = UserProfile.objects.get(username=username) if not user.check_password(password): raise ValidationError("Invalid password") except User.DoesNotExist: raise ValidationError("User {} doesn't exist".format(username)) return MessagesCreator.get_session(self.__generate_session__(user.id))
def register(self, username, password, email, sex): check_user(username) self.__check_password(password) self.__check_email__(email) user_profile = UserProfile(username=username, email=email, sex_str=sex) user_profile.set_password(password) user_profile.save() RoomUsers(user_id=user_profile.id, room_id=settings.ALL_ROOM_ID, notifications=False).save() user_data = { VarNames.ROOMS: [{ VarNames.ROOM_ID: settings.ALL_ROOM_ID, VarNames.ROOM_USERS: list( RoomUsers.objects.filter(room_id=ALL_ROOM_ID).values_list( 'user_id', flat=True)) }], VarNames.EVENT: Actions.CREATE_NEW_USER, VarNames.HANDLER_NAME: HandlerNames.ROOM, } user_data.update( RedisPrefix.set_js_user_structure(user_profile.id, user_profile.username, user_profile.sex, None)) global_redis.async_redis_publisher.publish( settings.ALL_ROOM_ID, json.dumps(user_data), ) if email: yield from self.__send_sign_up_email(user_profile) return MessagesCreator.get_session( self.__generate_session__(user_profile.id))