def reset_password(self): user = self.profile.user password = self.set_new_password(user) message = self._build_reset_password_message(password) user.save() self.profile.save() send_email.delay('NECOC Password Reset', message, settings.DEFAULT_FROM_EMAIL, [self.profile.email])
def setup_new_user(self, username, group_id): user = User(username=username, group=group_id).save() password = self.set_new_password(user) message = self._build_new_user_email_message(username, password) send_email.delay('Your NECOC Account', message, settings.DEFAULT_FROM_EMAIL, [self.profile.email]) if self.profile.phone and getattr(settings, 'SENDSMS_ON_PASSWORD_RESET', False): text = 'Your NECOC password has been set to %s' % password send_one_sms.delay(None, self.profile.phone, text) return user
def setup_new_user(self, username, group_id): user = User(username=username, group=group_id).save() password = self.set_new_password(user) message = self._build_new_user_email_message(username, password) send_email.delay('Your NECOC Account', message, settings.DEFAULT_FROM_EMAIL, [self.profile.email]) if self.profile.phone and getattr(settings, 'SENDSMS_ON_PASSWORD_RESET', False): text = 'Your NECOC password for user: %s has been set to %s' % ( username, password) send_one_sms.delay(None, self.profile.phone, text) return user
def post(self, request, *args, **kwargs): if request.POST.get('resetPass', None): form = PasswordForm(request.POST) if form.is_valid(): user = User.objects(username=form.cleaned_data['username'], email=form.cleaned_data['email']).first() profile = UserProfile.objects(user=user).first() if user: name = profile.name if profile else 'DMS User' phone = profile.phone if profile else '' subject = 'NECOC Password Reset Request' from_email = settings.DEFAULT_FROM_EMAIL hostname = settings.HOSTNAME admin_email = settings.ADMIN_EMAIL password = UserManager().make_random_password() user.set_password(password) user.save() message = settings.RESET_PASSWORD_MESSAGE % { 'name': name, 'hostname': hostname, 'password': password, 'admin_email': admin_email } recipient_list = [user.email] send_email.delay(subject, message, from_email, recipient_list) if phone and getattr(settings, 'SENDSMS_ON_PASSWORD_RESET', False): text = 'Your NECOC password for user: %s has been reset to %s' % ( user.username, password) send_one_sms.delay(None, phone, text) else: form.add_error(None, 'No user with matching Username and Email') else: form.add_error(None, 'Invalid data') return render(request, 'login.html', {'form': form}) else: login_form = LoginForm(request.POST) if login_form.is_valid(): user = authenticate( username=(login_form.cleaned_data['username']), password=(login_form.cleaned_data['password'])) if user: login(request, user) return redirect('/') login_form.add_error(None, 'Username or Password is invalid') return render(request, 'login.html', {'login_form': login_form})
def notify_new_disaster_status(sender, instance=None, created=False, **kwargs): if sender.__name__ == 'Disaster': if not created: instance = kwargs.get('document') if instance.pk is not None: orig = sender.objects.get(pk=instance.pk) if not orig.status == instance.status: name = 'DMS User' subject = 'Status of Disaster Risk has changed' from_email = settings.DEFAULT_FROM_EMAIL locations = [loc.name for loc in instance.locations] message = settings.DISASTER_STATUS_CHANGE_MESSAGE % \ {'name': name, 'disaster_name': instance.name.name, 'locations': '['+ ','.join(locations)+']', 'original_status': orig.status, 'new_status': instance.status} recipient_list = settings.DISASTER_NOTIFY_STATUS send_email.delay(subject, message, from_email, recipient_list)
def post(self, request, *args, **kwargs): if request.POST.get('resetPass', None): form = PasswordForm(request.POST) if form.is_valid(): user = User.objects(username=form.cleaned_data['username'], email=form.cleaned_data['email']).first() profile = UserProfile.objects(user=user).first() if user: name = profile.name if profile else 'DMS User' phone = profile.phone if profile else '' subject = 'NECOC Password Reset Request' from_email = settings.DEFAULT_FROM_EMAIL hostname = settings.HOSTNAME admin_email = settings.ADMIN_EMAIL password = UserManager().make_random_password() user.set_password(password) user.save() message = settings.RESET_PASSWORD_MESSAGE % { 'name': name, 'hostname': hostname, 'password': password, 'admin_email': admin_email} recipient_list = [user.email] send_email.delay(subject, message, from_email, recipient_list) if phone and getattr(settings, 'SENDSMS_ON_PASSWORD_RESET', False): text = 'Your NECOC password has been reset to %s' % password send_one_sms.delay(None, phone, text) else: form.add_error(None, 'No user with matching Username and Email') else: form.add_error(None, 'Invalid data') return render(request, 'login.html', {'form': form}) else: login_form = LoginForm(request.POST) if login_form.is_valid(): user = authenticate(username=(login_form.cleaned_data['username']), password=(login_form.cleaned_data['password'])) if user: login(request, user) return redirect('/') login_form.add_error(None, 'Username or Password is invalid') return render(request, 'login.html', {'login_form': login_form})
def notify_password_change(self): message = self._build_change_password_notification_message() send_email.delay('Your NECOC Account', message, settings.DEFAULT_FROM_EMAIL, [self.profile.email])