Skip to content

Commit

Permalink
Merge pull request #295 from UpyExplorer/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
FernandoCelmer authored May 6, 2023
2 parents 605f24d + a8d3692 commit bf93201
Showing 1 changed file with 64 additions and 32 deletions.
96 changes: 64 additions & 32 deletions modules/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def get_context_data(self, **kwargs):
return context

def form_valid(self, form):
request = self.request
user = form.save(commit=False)

if settings.DISABLE_USERNAME:
Expand All @@ -134,36 +133,41 @@ def form_valid(self, form):
user.save()
management.call_command(setup_company.Command(), user.id)
except Exception:
messages.error(request, _('Error!'))
messages.error(
request=self.request,
message=_('Error!')
)
return redirect('account:sign_up')

if settings.DISABLE_USERNAME:
user.username = f'user_{user.id}'
user.save()

if settings.ENABLE_USER_ACTIVATION:
code = get_random_string(20)

act = Activation()
act.code = code
act.user = user
act.save()
Activation(
code=code,
user=user
).save()

send_activation_email(request, user.email, code)
send_activation_email(self.request, user.email, code)

messages.success(
request, _('You are signed up. To activate the account, follow the link sent to the mail.'))
request=self.request,
message=_('You are signed up. To activate the account, follow the link sent to the mail.')
)
else:
raw_password = form.cleaned_data['password1']
user = authenticate(username=user.username, password=raw_password)
login(request, user)
login(self.request, user)

messages.success(request, _('You are successfully signed up!'))
messages.success(
request=self.request,
message=_('You are successfully signed up!')
)

return redirect('dashboard')


class ActivateView(View):

@staticmethod
def get(request, code):
act = get_object_or_404(Activation, code=code)
Expand All @@ -176,7 +180,10 @@ def get(request, code):
# Remove the activation record
act.delete()

messages.success(request, _('You have successfully activated your account!'))
messages.success(
request=request,
message=_('You have successfully activated your account!')
)

return redirect('account:log_in')

Expand All @@ -199,14 +206,17 @@ def form_valid(self, form):

code = get_random_string(20)

act = Activation()
act.code = code
act.user = user
act.save()
Activation(
code=code,
user=user
).save()

send_activation_email(self.request, user.email, code)

messages.success(self.request, _('A new activation code has been sent to your email address.'))
messages.success(
request=self.request,
message=_('A new activation code has been sent to your email address.')
)

return redirect('account:resend_activation_code')

Expand Down Expand Up @@ -262,7 +272,10 @@ def form_valid(self, form):
user.last_name = form.cleaned_data['last_name']
user.save()

messages.success(self.request, _('Profile data has been successfully updated.'))
messages.success(
request=self.request,
message=_('Profile data has been successfully updated.')
)

return redirect('account:change_profile')

Expand Down Expand Up @@ -302,25 +315,32 @@ def form_valid(self, form):
if settings.ENABLE_ACTIVATION_AFTER_EMAIL_CHANGE:
code = get_random_string(20)

act = Activation()
act.code = code
act.user = user
act.email = email
act.save()
Activation(
code=code,
user=user,
email=email
).save()

send_activation_change_email(self.request, email, code)

messages.success(self.request, _('To complete the change of email address, click on the link sent to it.'))
messages.success(
request=self.request,
message=_('To complete the change of email address, click on the link sent to it.')
)
else:
user.email = email
user.save()

messages.success(self.request, _('Email successfully changed.'))
messages.success(
request=self.request,
message=_('Email successfully changed.')
)

return redirect('account:change_email')


class ChangeEmailActivateView(View):

@staticmethod
def get(request, code):
act = get_object_or_404(Activation, code=code)
Expand All @@ -333,7 +353,10 @@ def get(request, code):
# Remove the activation record
act.delete()

messages.success(request, _('You have successfully changed your email!'))
messages.success(
request=request,
message=_('You have successfully changed your email!')
)

return redirect('account:change_email')

Expand All @@ -346,7 +369,10 @@ def form_valid(self, form):
user = form.user_cache
send_forgotten_username_email(user.email, user.username)

messages.success(self.request, _('Your username has been successfully sent to your email.'))
messages.success(
request=self.request,
message=_('Your username has been successfully sent to your email.')
)

return redirect('account:remind_username')

Expand Down Expand Up @@ -375,7 +401,10 @@ def form_valid(self, form):
# Re-authentication
login(self.request, user)

messages.success(self.request, _('Your password was changed.'))
messages.success(
request=self.request,
message=_('Your password was changed.')
)

return redirect('account:change_password')

Expand All @@ -387,7 +416,10 @@ def form_valid(self, form):
# Change the password
form.save()

messages.success(self.request, _('Your password has been set. You may go ahead and login now.'))
messages.success(
request=self.request,
message=_('Your password has been set. You may go ahead and login now.')
)

return redirect('account:log_in')

Expand Down

0 comments on commit bf93201

Please sign in to comment.