def _login_user(request, user): if not user.is_active: return inactive_user_http_response() # This is a total hack because we don't care to write a backend for the above authenticate method. user.backend = settings.AUTHENTICATION_BACKENDS[0] auth.login(request, user) return { 'user': PrivateUserDetails.from_id(user.id).to_client(), 'user_bio': user.userinfo.bio_text, 'user_subscribed_to_starred': is_subscribed(user, 'starred'), 'comment_count': QuestComment.all_objects.filter(author=user).count(), 'quest_count': Quest.all_objects.filter(author=user).count(), 'sessionid': request.session.session_key, 'login': True, 'heavy_state_sync': heavy_state_sync(request.user, app_version=request.app_version, app_version_tuple=request.app_version_tuple), }
def process_request(self, request): if request.user.is_authenticated() and not request.user.is_active: if request.META['PATH_INFO'].startswith('/api'): #TODO this is duplicating _handle_json_response work return inactive_user_http_response() else: logout(request) return HttpResponseRedirect('/')
def process_request(self, request): if request.user.is_authenticated() and not request.user.is_active: if request.META['PATH_INFO'].startswith('/api'): #TODO this is duplicating _handle_json_response work return inactive_user_http_response() else: logout(request) return HttpResponseRedirect('/')
def _login(request, password, username=None, email=None): def wrong_password(): raise ValidationError({ 'password': [_("The password you entered is incorrect. Please try again (make sure your caps lock is off).")], }) def wrong_username(username): raise ValidationError({ 'username': [_(u"""The username you entered, "%(username)s", doesn't exist. Please try again, or enter the email address you used to sign up.""" % {'username': username})], }) if not username and not email: raise ValidationError({'username': [_("Username is required to sign in.")]}) if username is not None and not all(ord(char) < 256 for char in username): wrong_username(username) user = auth.authenticate(username=username, password=password, email=email) if user is None: try: try: User.objects.get(Q(username=username) | Q(email=email) | Q(email=username)) except User.MultipleObjectsReturned: pass wrong_password() except User.DoesNotExist: wrong_username(username) if not user.is_active: return inactive_user_http_response() auth.login(request, user) return { 'user': PrivateUserDetails.from_id(user.id).to_client(), 'user_bio': user.userinfo.bio_text, 'user_subscribed_to_starred': is_subscribed(user, 'starred'), 'comment_count': QuestComment.all_objects.filter(author=user).count(), 'quest_count': Quest.all_objects.filter(author=user).count(), 'sessionid': request.session.session_key, 'migrated_from_canvas_account': False, 'login': True, 'heavy_state_sync': heavy_state_sync(request.user, app_version=request.app_version, app_version_tuple=request.app_version_tuple), }
def _login_user(request, user): if not user.is_active: return inactive_user_http_response() # This is a total hack because we don't care to write a backend for the above authenticate method. user.backend = settings.AUTHENTICATION_BACKENDS[0] auth.login(request, user) return { 'user': PrivateUserDetails.from_id(user.id).to_client(), 'user_bio': user.userinfo.bio_text, 'user_subscribed_to_starred': is_subscribed(user, 'starred'), 'comment_count': QuestComment.all_objects.filter(author=user).count(), 'quest_count': Quest.all_objects.filter(author=user).count(), 'sessionid': request.session.session_key, 'login': True, 'heavy_state_sync': heavy_state_sync(request.user, app_version=request.app_version, app_version_tuple=request.app_version_tuple), }
def login_with_facebook(request, facebook_access_token): try: fb_user = FacebookUser.get_from_access_token(facebook_access_token) except FacebookUser.DoesNotExist: raise PermissionDenied("No DrawQuest user exists for this Facebook account.") user = fb_user.user if not user.is_active: return inactive_user_http_response() # this is a total hack because we don't care to write a backend for the above authenticate method user.backend = settings.AUTHENTICATION_BACKENDS[0] auth.login(request, user) return { 'user': PrivateUserDetails.from_id(user.id).to_client(), 'user_bio': user.userinfo.bio_text, 'user_subscribed_to_starred': is_subscribed(user, 'starred'), 'sessionid': request.session.session_key, }
def login_with_facebook(request, facebook_access_token): try: fb_user = FacebookUser.get_from_access_token(facebook_access_token) except FacebookUser.DoesNotExist: raise PermissionDenied( "No DrawQuest user exists for this Facebook account.") user = fb_user.user if not user.is_active: return inactive_user_http_response() # this is a total hack because we don't care to write a backend for the above authenticate method user.backend = settings.AUTHENTICATION_BACKENDS[0] auth.login(request, user) return { 'user': PrivateUserDetails.from_id(user.id).to_client(), 'user_bio': user.userinfo.bio_text, 'user_subscribed_to_starred': is_subscribed(user, 'starred'), 'sessionid': request.session.session_key, }
def _login(request, password, username=None, email=None): migrated_from_canvas_account = False def wrong_password(): raise ValidationError({ 'password': "******" "Please try again (make sure your caps lock is off)." }) def wrong_username(username): raise ValidationError({ 'username': """The username you entered, "{}", doesn't exist. """.format(username) + """Please try again, or enter the e-mail address you used to sign up.""" }) def get_username_from_email(email): if not email: wrong_username(email) try: return User.objects.get(email=email).username except User.DoesNotExist: wrong_username(email) if not username and not email: raise ValidationError({'username': "******"}) if not username: username = get_username_from_email(email) user = auth.authenticate(username=username, password=password) if user is None: # Maybe they entered an email into the username field? try: User.objects.get(username=username) except User.DoesNotExist: try: #TODO This might be broken - should probably pass username. username = get_username_from_email(email) user = auth.authenticate(username=username, password=password) except ValidationError: # No such username exists. # See if it's a example.com account we need to migrate over. if User.is_username_reserved(username): try: user = User.migrate_canvas_user(request, username, password, email=email) except ValidationError as e: wrong_password() else: migrated_from_canvas_account = True if user is None: wrong_password() if not user.is_active: return inactive_user_http_response() auth.login(request, user) return { 'user': PrivateUserDetails.from_id(user.id).to_client(), 'user_bio': user.userinfo.bio_text, 'user_subscribed_to_starred': is_subscribed(user, 'starred'), 'sessionid': request.session.session_key, 'migrated_from_canvas_account': migrated_from_canvas_account, }
def _login(request, password, username=None, email=None): migrated_from_canvas_account = False def wrong_password(): raise ValidationError({ 'password': "******" "Please try again (make sure your caps lock is off)." }) def wrong_username(username): raise ValidationError({ 'username': """The username you entered, "{}", doesn't exist. """.format( username) + """Please try again, or enter the e-mail address you used to sign up.""" }) def get_username_from_email(email): if not email: wrong_username(email) try: return User.objects.get(email=email).username except User.DoesNotExist: wrong_username(email) if not username and not email: raise ValidationError({'username': "******"}) if not username: username = get_username_from_email(email) user = auth.authenticate(username=username, password=password) if user is None: # Maybe they entered an email into the username field? try: User.objects.get(username=username) except User.DoesNotExist: try: #TODO This might be broken - should probably pass username. username = get_username_from_email(email) user = auth.authenticate(username=username, password=password) except ValidationError: # No such username exists. # See if it's a example.com account we need to migrate over. if User.is_username_reserved(username): try: user = User.migrate_canvas_user(request, username, password, email=email) except ValidationError as e: wrong_password() else: migrated_from_canvas_account = True if user is None: wrong_password() if not user.is_active: return inactive_user_http_response() auth.login(request, user) return { 'user': PrivateUserDetails.from_id(user.id).to_client(), 'user_bio': user.userinfo.bio_text, 'user_subscribed_to_starred': is_subscribed(user, 'starred'), 'sessionid': request.session.session_key, 'migrated_from_canvas_account': migrated_from_canvas_account, }
def _login(request, password, username=None, email=None): def wrong_password(): raise ValidationError({ 'password': [ _("The password you entered is incorrect. Please try again (make sure your caps lock is off)." ) ], }) def wrong_username(username): raise ValidationError({ 'username': [ _(u"""The username you entered, "%(username)s", doesn't exist. Please try again, or enter the email address you used to sign up.""" % {'username': username}) ], }) if not username and not email: raise ValidationError( {'username': [_("Username is required to sign in.")]}) if username is not None and not all(ord(char) < 256 for char in username): wrong_username(username) user = auth.authenticate(username=username, password=password, email=email) if user is None: try: try: User.objects.get( Q(username=username) | Q(email=email) | Q(email=username)) except User.MultipleObjectsReturned: pass wrong_password() except User.DoesNotExist: wrong_username(username) if not user.is_active: return inactive_user_http_response() auth.login(request, user) return { 'user': PrivateUserDetails.from_id(user.id).to_client(), 'user_bio': user.userinfo.bio_text, 'user_subscribed_to_starred': is_subscribed(user, 'starred'), 'comment_count': QuestComment.all_objects.filter(author=user).count(), 'quest_count': Quest.all_objects.filter(author=user).count(), 'sessionid': request.session.session_key, 'migrated_from_canvas_account': False, 'login': True, 'heavy_state_sync': heavy_state_sync(request.user, app_version=request.app_version, app_version_tuple=request.app_version_tuple), }