def delete_accounts_from_google(self, request, queryset): """Deletes the user from Google Apps database """ gam = GoogleAppsManager() opts = self.model._meta app_label = opts.app_label deletable_objects = [profile for profile in queryset] # The user has already confirmed the deletion. # Do the deletion and return a None to display the change list view again. if request.POST.get('post'): for profile in queryset: try: gam.delete_account(profile.user.username) profile.google_account_created = False profile.save() except Exception, e: messages.error(request, 'Error while deleting %s. Error : %s' % (profile.register_number, e)) else: messages.success(request, 'Successfully deleted %s' % profile.register_number) return None
def delete_accounts_from_google(self, request, queryset): """Deletes the user from Google Apps database """ gam = GoogleAppsManager() opts = self.model._meta app_label = opts.app_label deletable_objects = [profile for profile in queryset] # The user has already confirmed the deletion. # Do the deletion and return a None to display the change list view again. if request.POST.get('post'): for profile in queryset: try: gam.delete_account(profile.user.username) profile.google_account_created = False profile.save() except Exception, e: messages.error( request, 'Error while deleting %s. Error : %s' % (profile.register_number, e)) else: messages.success( request, 'Successfully deleted %s' % profile.register_number) return None
def save(self): username = self.user.username password = self.cleaned_data['new_password1'] gam = GoogleAppsManager() gam.change_password(username, password) return self.user
def reactivate_account(self, request, queryset): gam = GoogleAppsManager() for profile in queryset: try: gam.unsuspend_user(profile.user.username) profile.active = True profile.save() except Exception, e: messages.error(request, 'Error while reactivating %s. Reason : %s' % (profile.user.username, e)) else: messages.success(request, 'Reactivated %s' % profile.user.username)
def reactivate_account(self, request, queryset): gam = GoogleAppsManager() for profile in queryset: try: gam.unsuspend_user(profile.user.username) profile.active = True profile.save() except Exception, e: messages.error( request, 'Error while reactivating %s. Reason : %s' % (profile.user.username, e)) else: messages.success(request, 'Reactivated %s' % profile.user.username)
def create_account_in_google_apps(request, profile, password): username = profile.user.username first_name = profile.user.first_name last_name = profile.user.last_name college_email_id = profile.college_email_id nickname = college_email_id.split('@')[0] if profile.course.name == 'Staff': groupname = 'staff' else: groupname = profile.register_number[:5] if not college_email_id: messages.error(request, 'College Email Id is empty for %s' % username) return if profile.google_account_created: messages.error(request, 'College Email Id is already created for %s' % username) return try: gam = GoogleAppsManager() gam.create_account(username, password, first_name, last_name, nickname, groupname ) send_introduction_mail(first_name, college_email_id) profile.google_account_created = True profile.save() except Exception, e: messages.error(request, 'Error while creating %s. Error : %s' % (profile.register_number, e))
def create_accounts_in_google(self, request, queryset): """Creates the Google Apps account for the user """ gam = GoogleAppsManager() password = User.objects.make_random_password( length=8, allowed_chars='0123456789') for profile in queryset: accounts_manager.create_account_in_google_apps( request, profile, password)
def reset_password(self, request, queryset): gam = GoogleAppsManager() passwd = User.objects.make_random_password(length=6) for profile in queryset: if not profile.google_account_created: messages.error(request, 'No Google Apps account for %s' % profile.register_number) continue try: username = profile.register_number result = gam.change_password(username, passwd) except Exception, e: messages.error(request, 'Failed to update password for %s. Reason : %s' % (username, e)) else: messages.success(request, 'Successfully updated password for %s. New Password is %s' % (username, passwd))
def create_account_in_google_apps(request, profile, password): username = profile.user.username first_name = profile.user.first_name last_name = profile.user.last_name college_email_id = profile.college_email_id nickname = college_email_id.split('@')[0] if profile.course.name == 'Staff': groupname = 'staff' else: groupname = profile.register_number[:5] if not college_email_id: messages.error(request, 'College Email Id is empty for %s' % username) return if profile.google_account_created: messages.error(request, 'College Email Id is already created for %s' % username) return try: gam = GoogleAppsManager() gam.create_account(username, password, first_name, last_name, nickname, groupname) send_introduction_mail(first_name, college_email_id) profile.google_account_created = True profile.save() except Exception, e: messages.error( request, 'Error while creating %s. Error : %s' % (profile.register_number, e))
def reset_password(self, request, queryset): gam = GoogleAppsManager() passwd = User.objects.make_random_password(length=8, allowed_chars='0123456789') for profile in queryset: if not profile.google_account_created: messages.error( request, 'No Google Apps account for %s' % profile.register_number) continue try: username = profile.register_number result = gam.change_password(username, passwd) except Exception, e: messages.error( request, 'Failed to update password for %s. Reason : %s' % (username, e)) else: messages.success( request, 'Successfully updated password for %s. New Password is %s' % (username, passwd))