You could read AdminSite.login and .login to see what is actually happening inside Django. If you want a cleaner solution I suggest to use a boolean inside user model instead of relying on last_login so you could just check er instead of my hack into request.POST. Return HttpResponseRedirect(reverse('admin:password_change')) ![]() If new_user and er = user and isinstance(r, HttpResponseRedirect): # Successful logins will result in a redirect. R = super(MyAdminSite, self).login(request, extra_context) Username = ('username') # Hack to find user before its last_login set to now. Paste at the top of urls.py from ntrib import adminįrom import AdminSiteįrom import Userįrom import reverseįrom django.http import HttpResponseRedirectĭef login(self, request, extra_context=None): My implementation is a bit hacky but small: Login/logout views are inside Django AdminSite class (the one you usually access by admin.site). User_logged_in.connect(change_password_first_time)ĭjango admin is not that configurable. You can use signal to check the logged in user and apply the config_login_allowed logic here.? from import user_logged_inĭef change_password_first_time(sender, user, request, **kwargs): But What if the user not set the password in first day and comes next day ?.What if user not set the password in the first time and how you're going to handle second attempt.? This time last_long not None.Note: There is lot of edge cases you have to consider for this approach. Raise ValidationError(mark_safe('Hey first time user please reset your password here. class CustomAdminLoginForm(AuthenticationForm): ![]() When overriding the Admin we have to get rid of Django default admin from app.admin import admin_siteĪuthenticationForm have the confirm_login_allowed method use this to grant permission to login in or not login in. To begin, please Launch GoRev by double clicking on the GoRev Launcher icon on your device. Customise Django admin using AdminSite and use login_form attribute to give the custom login form for the Admin login page. Once you have received your GoRev Account Information from your Authorized Delegate, you are ready to Login to GoRev as a First Time User.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |