Skip to content

Commit 2ac2062

Browse files
Merge pull request #357 from MasoniteFramework/master
Next Minor
2 parents ad93677 + 9429b49 commit 2ac2062

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

src/masonite/drivers/authentication/AuthJwtDriver.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def save(self, _, **kwargs):
8989
serialized_dictionary = model.serialize()
9090
serialized_dictionary.update({"expired": cookie_expire_time("5 minutes")})
9191
token = self.jwt.encode(serialized_dictionary, KEY, algorithm="HS256")
92-
token = bytes(token).decode("utf-8")
92+
if isinstance(token, bytes):
93+
token = bytes(token).decode("utf-8")
9394
self.request.cookie("token", token)
9495

9596
def delete(self):

src/masonite/helpers/misc.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,15 @@ def __new__(cls, *args):
105105

106106

107107
def deprecated(message):
108+
warnings.simplefilter("default", DeprecationWarning)
109+
108110
def deprecated_decorator(func):
109111
def deprecated_func(*args, **kwargs):
110112
warnings.warn(
111113
"{} is a deprecated function. {}".format(func.__name__, message),
112114
category=DeprecationWarning,
113115
stacklevel=2,
114116
)
115-
warnings.simplefilter("default", DeprecationWarning)
116117
return func(*args, **kwargs)
117118

118119
return deprecated_func

src/masonite/providers/RouteProvider.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ def boot(self, router: Route, request: Request, response: Response):
118118

119119
"""No Response was found in the for loop so let's set an arbitrary response now.
120120
"""
121-
response.view("Route not found. Error 404", status=404)
122121
# If the route exists but not the method is incorrect
123-
if request.is_status(404) and request.route_exists(request.path):
122+
if request.route_exists(request.path):
124123
response.view("Method not allowed", status=405)
124+
else:
125+
response.view("Route not found. Error 404", status=404)

src/masonite/request.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,16 @@ def __getattr__(self, key):
955955
raise AttributeError("class 'Request' has no attribute {}".format(key))
956956

957957
def with_errors(self, errors):
958-
self.session.flash("errors", errors)
958+
"""Easily attach errors message to session request."""
959+
return self.with_flash("error", errors)
960+
961+
def with_success(self, success):
962+
"""Easily attach success message to session request."""
963+
return self.with_flash("success", success)
964+
965+
def with_flash(self, key, value):
966+
"""Easily attach data to session request."""
967+
self.session.flash(key, value)
959968
return self
960969

961970
def reset_redirections(self):

tests/core/test_session.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def test_can_redirect_with_inputs(self):
141141

142142
def test_can_redirect_with_bytes_inputs(self):
143143
for driver in ('memory', 'cookie'):
144-
144+
145145
request = self.container.make('Request')
146146
session = self.container.make('SessionManager').driver(driver)
147147
request.request_variables = {
@@ -167,3 +167,20 @@ def test_intended_returns_correct_url(self):
167167
# Assert redirect intended method resets the redirection
168168
request.redirect_intended()
169169
self.assertEqual(request.session.get('__intend'), None)
170+
171+
def test_with_flash(self):
172+
request = self.container.make('Request')
173+
request.redirect('/dashboard').with_flash('success', 'Ok')
174+
self.assertEqual(request.session.get('success'), 'Ok')
175+
request.redirect('/dashboard').with_flash('any_key', 'any_value')
176+
self.assertEqual(request.session.get('any_key'), 'any_value')
177+
178+
def test_with_errors(self):
179+
request = self.container.make('Request')
180+
request.redirect('/dashboard').with_errors('Form error')
181+
self.assertEqual(request.session.get('error'), 'Form error')
182+
183+
def test_with_success(self):
184+
request = self.container.make('Request')
185+
request.redirect('/dashboard').with_success('Created !')
186+
self.assertEqual(request.session.get('success'), 'Created !')

0 commit comments

Comments
 (0)