-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into remove-start-response-provider
- Loading branch information
Showing
5 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""A PasswordController Module.""" | ||
|
||
import uuid | ||
|
||
from masonite import env, Mail, Session | ||
from masonite.auth import Auth | ||
from masonite.helpers import password as bcrypt_password | ||
from masonite.request import Request | ||
from masonite.view import View | ||
|
||
from config.auth import AUTH | ||
|
||
|
||
class PasswordController: | ||
"""Password Controller.""" | ||
|
||
def forget(self, view: View, request: Request): | ||
return view.render('auth/forget', {'app': request.app().make('Application'), 'Auth': Auth(request)}) | ||
|
||
def reset(self, request: Request): | ||
token = request.param('token') | ||
user = AUTH['model'].where('remember_token', token).first() | ||
if user: | ||
return view('auth/reset', {'token': token, 'app': request.app().make('Application'), 'Auth': Auth(request)}) | ||
|
||
def send(self, request: Request, session: Session, mail: Mail): | ||
email = request.input('email') | ||
user = AUTH['model'].where('email', email).first() | ||
|
||
if user: | ||
if not user.remember_token: | ||
user.remember_token = str(uuid.uuid4()) | ||
user.save() | ||
message = 'Please visit {}/password/{}/reset to reset your password'.format(env('SITE', 'http://localhost:8000'), user.remember_token) | ||
mail.subject('Reset Password Instructions').to(email).send(message) | ||
session.flash('success', 'Email sent. Follow the instruction in the email to reset your password.') | ||
return request.redirect('/password') | ||
else: | ||
session.flash('error', 'Could not send reset email. Please enter correct email.') | ||
return request.redirect('/password') | ||
|
||
def update(self, request: Request): | ||
user = AUTH['model'].where('remember_token', request.param('token')).first() | ||
if user: | ||
user.password = bcrypt_password(request.input('password')) | ||
user.save() | ||
return request.redirect('/login') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{% extends 'auth/base.html' %} | ||
|
||
{% block content %} | ||
<div class="row my-5"> | ||
<div class="col-md-12"> | ||
<div class="row"> | ||
<div class="col-md-6 mx-auto"> | ||
{% if session().has('error') %} | ||
<div class="alert alert-danger" role="alert"> | ||
{{ session().get('error') }} | ||
</div> | ||
{% endif %} | ||
{% if session().has('success') %} | ||
<div class="alert alert-success" role="alert"> | ||
{{ session().get('success') }} | ||
</div> | ||
{% endif %} | ||
<div class="card rounded-1"> | ||
<div class="card-header"> | ||
<h5 class="mb-0">Password Reset</h5> | ||
</div> | ||
<div class="card-body"> | ||
<form class="form" action="/password" method="POST"> | ||
{{ csrf_field }} | ||
<div class="form-group"> | ||
<label for="">Email</label> | ||
<input type="text" class="form-control form-control-md rounded-0" name="email"> | ||
</div> | ||
<button type="submit" class="btn btn-success btn-md float-right">Send reset link</button> | ||
<a href="{{ route('forgot.password') }}" class="btn btn-primary btn-md mx-1 float-right">Forgot Password</a> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{% extends 'auth/base.html' %} | ||
|
||
{% block content %} | ||
<div class="row my-5"> | ||
<div class="col-md-12"> | ||
<div class="row"> | ||
<div class="col-md-6 mx-auto"> | ||
{% if session().has('error') %} | ||
<div class="alert alert-danger" role="alert"> | ||
{{ session().get('error') }} | ||
</div> | ||
{% endif %} | ||
{% if session().has('success') %} | ||
<div class="alert alert-success" role="alert"> | ||
{{ session().get('success') }} | ||
</div> | ||
{% endif %} | ||
<div class="card rounded-1"> | ||
<div class="card-header"> | ||
<h5 class="mb-0">Reset Password</h5> | ||
</div> | ||
<div class="card-body"> | ||
<form class="form" action="/password/{{token}}/reset" method="POST"> | ||
{{ csrf_field }} | ||
<div class="form-group"> | ||
<label for="">New Password</label> | ||
<input type="password" class="form-control form-control-md rounded-0" name="password"> | ||
</div> | ||
<button type="submit" class="btn btn-success btn-md float-right">Reset</button> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |