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 self.__generate_session__(user_profile.id)
def post(self, request): rp = request.POST logger.info('Got register request %s', hide_fields(rp, ('password', 'repeatpassword'))) (username, password, email) = (rp.get('username'), rp.get('password'), rp.get('email')) check_user(username) check_password(password) check_email(email) user_profile = UserProfile(username=username, email=email, sex_str=rp.get('sex')) user_profile.set_password(password) create_user_model(user_profile) # You must call authenticate before you can call login auth_user = authenticate(username=username, password=password) if email: send_sign_up_email(user_profile, request.get_host(), request) djangologin(request, auth_user) return HttpResponse(settings.VALIDATION_IS_OK, content_type='text/plain')
def post(self, request): try: rp = request.POST logger.info('Got register request %s', hide_fields(rp, ('password', 'repeatpassword'))) (username, password, email) = (rp.get('username'), rp.get('password'), rp.get('email')) check_user(username) check_password(password) check_email(email) user_profile = UserProfile(username=username, email=email, sex_str=rp.get('sex')) user_profile.set_password(password) create_user_model(user_profile) # You must call authenticate before you can call login auth_user = authenticate(username=username, password=password) message = VALIDATION_IS_OK # redirect if email: send_email_verification(user_profile, request.get_host()) djangologin(request, auth_user) except ValidationError as e: message = e.message logger.debug('Rejecting request because "%s"', message) return HttpResponse(message, content_type='text/plain')
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))