def confirm_email(self, request: Request, view: View, auth: Auth, inertia: InertiaResponse): sign = Sign() token = sign.unsign(request.param("id")) if token is not None: tokenParts = token.split("::") if len(tokenParts) > 1: user = auth.auth_model.find(tokenParts[0]) if user.verified_at is None: timestamp = datetime.datetime.fromtimestamp( float(tokenParts[1])) now = datetime.datetime.now() timestamp_plus_10 = timestamp + datetime.timedelta( minutes=10) if now < timestamp_plus_10: user.verified_at = datetime.datetime.now() user.save() request.session.flash( 'success', 'Your email has successfully been verified.') return request.redirect("/") request.session.flash( 'error', 'Something went wrong. We could not verify your email address.') return request.redirect("/")
def confirm_email(self, request: Request, view: View, auth: Auth): """Confirm User email and show the correct response. Arguments: request {masonite.request.request} -- The Masonite request class. request {masonite.view.view} -- The Masonite view class. request {masonite.auth.auth} -- The Masonite Auth class. Returns: [type] -- [description] """ sign = Sign() token = sign.unsign(request.param('id')) if token is not None: tokenParts = token.split("::") if len(tokenParts) > 1: user = auth.auth_model.find(tokenParts[0]) if user.verified_at is None: timestamp = datetime.datetime.fromtimestamp(float(tokenParts[1])) now = datetime.datetime.now() timestamp_plus_10 = timestamp + datetime.timedelta(minutes=10) if now < timestamp_plus_10: user.verified_at = datetime.datetime.now() user.save() return view.render('auth/confirm', {'app': request.app().make('Application'), 'Auth': auth}) return view.render('auth/error', {'app': request.app().make('Application'), 'Auth': auth})
def test_unsigning_without_value(self): s = Sign(self.secret_key) s.sign('value') assert s.unsign() == 'value'
def test_unsigning_returns_decrypted_value_without_parameter(self): s = Sign(self.secret_key) assert s.unsign(s.sign('value')) == 'value'
def test_unsigning_returns_decrypted_value_with_parameter(): s = Sign(SECRET_KEY) assert s.unsign(s.sign('value')) == 'value'
def test_unsigning_without_value(): s = Sign(SECRET_KEY) s.sign('value') assert s.unsign() == 'value'