def reset_password_callback(request, user): """ Default implementation of ``kotti.reset_password_callback``. You can implement a custom function with the same signature and point the ``kotti.reset_password_callback`` setting to it. :param request: Current request :type request: :class:`kotti.request.Request` :param user: Principal, who's password was requested to be reset. :type user: :class:`kotti.security.Princial` :result: Any Pyramid response object, by default a redirect to to the same URL from where the password reset was called. :rtype: :class:`pyramid.httpexceptions.HTTPFound` """ email_set_password(user, request, template_name="kotti:templates/email-reset-password.pt") request.session.flash( _( u"You should be receiving an email with a link to reset your " u"password. Doing so will activate your account." ), "success", ) return HTTPFound(location=request.url)
def reset_password_callback(request, user): """ Default implementation of ``kotti.reset_password_callback``. You can implement a custom function with the same signature and point the ``kotti.reset_password_callback`` setting to it. :param request: Current request :type request: :class:`kotti.request.Request` :param user: Principal, who's password was requested to be reset. :type user: :class:`kotti.security.Princial` :result: Any Pyramid response object, by default a redirect to to the same URL from where the password reset was called. :rtype: :class:`pyramid.httpexceptions.HTTPFound` """ email_set_password( user, request, template_name="kotti:templates/email-reset-password.pt" ) request.session.flash( _( "You should be receiving an email with a link to reset your " "password. Doing so will activate your account." ), "success", ) return HTTPFound(location=request.url)
def test_email_set_password_add_query(self, db_session): from kotti.message import email_set_password user = Dummy(name="joe", email="*****@*****.**", title="Joe") email_set_password(user, DummyRequest(), add_query={"another": "param"}) assert self.mailer.send.called message = self.mailer.send.call_args[0][0] assert "another=param" in message.body
def test_email_set_password_add_query(self): from kotti.message import email_set_password user = Dummy(name=u'joe', email='*****@*****.**', title=u'Joe') email_set_password(user, DummyRequest(), add_query={'another': 'param'}) assert self.mailer.send.called message = self.mailer.send.call_args[0][0] assert 'another=param' in message.body
def add_user_success(self, appstruct): appstruct.pop('csrf_token', None) name = appstruct['name'] = appstruct['name'].lower() appstruct['email'] = appstruct['email'] and appstruct['email'].lower() get_principals()[name] = appstruct email_set_password(get_principals()[name], self.request) self.request.session.flash( _(u'The registration mail sent to ${email}.', mapping=dict(email=appstruct['email'])), 'success') return HTTPFound(location='/')
def test_email_set_password_add_query(self, db_session): from kotti.message import email_set_password user = Dummy(name=u'joe', email='*****@*****.**', title=u'Joe') email_set_password( user, DummyRequest(), add_query={'another': 'param'}) assert self.mailer.send.called message = self.mailer.send.call_args[0][0] assert 'another=param' in message.body
def login(context, request): """ Login view. Renders either the login or password forgot form templates or handles their form submission and redirects to came_from on success. :result: Either a redirect response or a dictionary passed to the template for rendering :rtype: pyramid.httpexceptions.HTTPFound or dict """ principals = get_principals() came_from = request.params.get( 'came_from', request.resource_url(context)) login, password = u'', u'' if 'submit' in request.POST: login = request.params['login'].lower() password = request.params['password'] user = _find_user(login) if (user is not None and user.active and principals.validate_password(password, user.password)): headers = remember(request, user.name) request.session.flash( _(u"Welcome, ${user}!", mapping=dict(user=user.title or user.name)), 'success') user.last_login_date = datetime.now() return HTTPFound(location=came_from, headers=headers) request.session.flash(_(u"Login failed."), 'error') if 'reset-password' in request.POST: login = request.params['login'] user = _find_user(login) if user is not None and user.active: email_set_password( user, request, template_name='kotti:templates/email-reset-password.pt') request.session.flash(_( u"You should be receiving an email with a link to reset your " u"password. Doing so will activate your account."), 'success') else: request.session.flash( _(u"That username or email is not known by this system."), 'error') headers = remember(request, user.name) return HTTPFound(location=came_from, headers=headers) return { 'url': request.application_url + '/@@login', 'came_from': came_from, 'login': login, 'password': password, 'register': asbool(get_settings()['kotti.register']), }
def login(context, request): """ Login view. Renders either the login or password forgot form templates or handles their form submission and redirects to came_from on success. :result: Either a redirect response or a dictionary passed to the template for rendering :rtype: pyramid.httpexceptions.HTTPFound or dict """ principals = get_principals() came_from = request.params.get('came_from', request.resource_url(context)) login, password = u'', u'' if 'submit' in request.POST: login = request.params['login'].lower() password = request.params['password'] user = _find_user(login) if (user is not None and user.active and principals.validate_password(password, user.password)): headers = remember(request, user.name) request.session.flash( _(u"Welcome, ${user}!", mapping=dict(user=user.title or user.name)), 'success') user.last_login_date = datetime.now() return HTTPFound(location=came_from, headers=headers) request.session.flash(_(u"Login failed."), 'error') if 'reset-password' in request.POST: login = request.params['login'] user = _find_user(login) if user is not None and user.active: email_set_password( user, request, template_name='kotti:templates/email-reset-password.pt') request.session.flash( _(u"You should be receiving an email with a link to reset your " u"password. Doing so will activate your account."), 'success') else: request.session.flash( _(u"That username or email is not known by this system."), 'error') return { 'url': request.application_url + '/@@login', 'came_from': came_from, 'login': login, 'password': password, 'register': asbool(get_settings()['kotti.register']), }
def test_email_set_password_other_template(self, db_session): from kotti.message import email_set_password user = Dummy(name=u'joe', email='*****@*****.**', title=u'Joe') email_set_password( user, DummyRequest(), template_name='kotti:templates/email-reset-password.pt') assert self.mailer.send.called message = self.mailer.send.call_args[0][0] assert message.subject.startswith('Reset your password')
def test_email_set_password_basic(self, db_session): from kotti.message import email_set_password user = Dummy(name="joe", email="*****@*****.**", title="Joe") email_set_password(user, DummyRequest()) assert hasattr(user, "confirm_token") assert self.mailer.send.called message = self.mailer.send.call_args[0][0] assert "Your registration" in message.subject assert "Joe" in message.body assert "Awesome site" in message.body
def test_email_set_password_basic(self, db_session): from kotti.message import email_set_password user = Dummy(name='joe', email='*****@*****.**', title='Joe') email_set_password(user, DummyRequest()) assert hasattr(user, 'confirm_token') assert self.mailer.send.called message = self.mailer.send.call_args[0][0] assert 'Your registration' in message.subject assert 'Joe' in message.body assert 'Awesome site' in message.body
def test_email_set_password_basic(self, db_session): from kotti.message import email_set_password user = Dummy(name=u'joe', email='*****@*****.**', title=u'Joe') email_set_password(user, DummyRequest()) assert hasattr(user, 'confirm_token') assert self.mailer.send.called message = self.mailer.send.call_args[0][0] assert 'Your registration' in message.subject assert 'Joe' in message.body assert 'Awesome site' in message.body
def add_user_success(self, appstruct): appstruct.pop("csrf_token", None) _massage_groups_in(appstruct) name = appstruct["name"] = appstruct["name"].lower() appstruct["email"] = appstruct["email"] and appstruct["email"].lower() send_email = appstruct.pop("send_email", False) get_principals()[name] = appstruct if send_email: email_set_password(get_principals()[name], self.request) self.request.session.flash( _("${title} was added.", mapping=dict(title=appstruct["title"])), "success" ) location = self.request.url.split("?")[0] + "?" + urlencode({"extra": name}) return HTTPFound(location=location)
def add_user_success(self, appstruct): appstruct.pop('csrf_token', None) _massage_groups_in(appstruct) name = appstruct['name'] = appstruct['name'].lower() appstruct['email'] = appstruct['email'] and appstruct['email'].lower() send_email = appstruct.pop('send_email', False) get_principals()[name] = appstruct if send_email: email_set_password(get_principals()[name], self.request) self.request.session.flash(_(u'${title} was added.', mapping=dict(title=appstruct['title'])), 'success') location = self.request.url.split('?')[0] + '?' + urlencode( {'extra': name}) return HTTPFound(location=location)
def add_user_success(self, appstruct): appstruct.pop('csrf_token', None) _massage_groups_in(appstruct) name = appstruct['name'] = appstruct['name'].lower() appstruct['email'] = appstruct['email'] and appstruct['email'].lower() send_email = appstruct.pop('send_email', False) get_principals()[name] = appstruct if send_email: email_set_password(get_principals()[name], self.request) self.request.session.flash(_(u'${title} added.', mapping=dict(title=appstruct['title'])), 'success') location = self.request.url.split('?')[0] + '?' + urlencode( {'extra': name}) return HTTPFound(location=location)
def login(context, request): """ Login view. Renders either the login or password forgot form templates or handles their form submission and redirects to came_from on success. :result: Either a redirect response or a dictionary passed to the template for rendering :rtype: pyramid.httpexceptions.HTTPFound or dict """ principals = get_principals() came_from = request.params.get("came_from", request.resource_url(context)) login, password = u"", u"" if "submit" in request.POST: login = request.params["login"].lower() password = request.params["password"] user = _find_user(login) if user is not None and user.active and principals.validate_password(password, user.password): headers = remember(request, user.name) request.session.flash(_(u"Welcome, ${user}!", mapping=dict(user=user.title or user.name)), "success") user.last_login_date = datetime.now() return HTTPFound(location=came_from, headers=headers) request.session.flash(_(u"Login failed."), "error") if "reset-password" in request.POST: login = request.params["login"] user = _find_user(login) if user is not None and user.active: email_set_password(user, request, template_name="kotti:templates/email-reset-password.pt") request.session.flash( _( u"You should be receiving an email with a link to reset your " u"password. Doing so will activate your account." ), "success", ) else: request.session.flash(_(u"That username or email is not known by this system."), "error") return { "url": request.application_url + "/@@login", "came_from": came_from, "login": login, "password": password, "register": asbool(get_settings()["kotti.register"]), }
def add_user_success(self, appstruct): appstruct.pop("csrf_token", None) _massage_groups_in(appstruct) name = appstruct["name"] = appstruct["name"].lower() appstruct["email"] = appstruct["email"] and appstruct["email"].lower() send_email = appstruct.pop("send_email", False) get_principals()[name] = appstruct if send_email: email_set_password(get_principals()[name], self.request) self.request.session.flash( _("${title} was added.", mapping=dict(title=appstruct["title"])), "success") location = self.request.url.split("?")[0] + "?" + urlencode( {"extra": name}) return HTTPFound(location=location)
def login(context, request): principals = get_principals() came_from = request.params.get( 'came_from', request.resource_url(context)) login, password = u'', u'' if 'submit' in request.POST: login = request.params['login'].lower() password = request.params['password'] user = _find_user(login) if (user is not None and user.active and principals.validate_password(password, user.password)): headers = remember(request, login) request.session.flash( _(u"Welcome, ${user}!", mapping=dict(user=user.title or user.name)), 'success') user.last_login_date = datetime.now() return HTTPFound(location=came_from, headers=headers) request.session.flash(_(u"Login failed."), 'error') if 'reset-password' in request.POST: login = request.params['login'] user = _find_user(login) if user is not None: email_set_password( user, request, template_name='kotti:templates/email-reset-password.pt') request.session.flash(_( u"You should receive an email with a link to reset your " u"password momentarily."), 'success') else: request.session.flash( _(u"That username or email is not known to us."), 'error') return { 'url': request.application_url + '/@@login', 'came_from': came_from, 'login': login, 'password': password, }
def login(context, request): principals = get_principals() came_from = request.params.get( 'came_from', request.resource_url(context)) login, password = u'', u'' if 'submit' in request.POST: login = request.params['login'].lower() password = request.params['password'] user = _find_user(login) if (user is not None and user.active and principals.validate_password(password, user.password)): headers = remember(request, user.name) request.session.flash( _(u"Welcome, ${user}!", mapping=dict(user=user.title or user.name)), 'success') user.last_login_date = datetime.now() return HTTPFound(location=came_from, headers=headers) request.session.flash(_(u"Login failed."), 'error') if 'reset-password' in request.POST: login = request.params['login'] user = _find_user(login) if user is not None and user.active: email_set_password( user, request, template_name='kotti:templates/email-reset-password.pt') request.session.flash(_( u"You should receive an email with a link to reset your " u"password momentarily."), 'success') else: request.session.flash( _(u"That username or email is not known to us."), 'error') return { 'url': request.application_url + '/@@login', 'came_from': came_from, 'login': login, 'password': password, }