Beispiel #1
0
 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
Beispiel #3
0
    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})
Beispiel #4
0
    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})
Beispiel #5
0
 def post_save(self, obj, created=True):
     auto_response_enabled = AdminSetting.objects(**dict(name='enable_automatic_response', yes_no=True)).first()
     if auto_response_enabled:
         send_one_sms.delay(obj)