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: send_set_password(user, request, templates="reset-password") 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 test_send_set_password_other_template(self): from kotti.message import send_set_password user = Dummy(name=u'joe', email='*****@*****.**', title=u'Joe') send_set_password(user, DummyRequest(), templates='reset-password') assert self.mailer.send.called message = self.mailer.send.call_args[0][0] assert 'Reset your password' in message.subject
def test_send_set_password_add_query(self): from kotti.message import send_set_password user = Dummy(name=u'joe', email='*****@*****.**', title=u'Joe') send_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(context, request, appstruct): _massage_groups_in(appstruct) name = appstruct['name'].lower() send_email = appstruct.pop('send_email', False) get_principals()[name] = appstruct if send_email: send_set_password(get_principals()[name], request) request.session.flash(u'%s added.' % appstruct['title'], 'success') location = request.url.split('?')[0] + '?' + urlencode({'extra': name}) return HTTPFound(location=location)
def add_user(context, request, appstruct): _massage_groups_in(appstruct) name = appstruct["name"].lower() send_email = appstruct.pop("send_email", False) get_principals()[name] = appstruct if send_email: send_set_password(get_principals()[name], request) request.session.flash(u"%s added." % appstruct["title"], "success") location = request.url.split("?")[0] + "?" + urlencode({"extra": name}) return HTTPFound(location=location)
def test_send_set_password_basic(self): from kotti.message import send_set_password user = Dummy(name=u'joe', email='*****@*****.**', title=u'Joe') send_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_send_set_password_other_template_entirely(self): from kotti.message import send_set_password user = Dummy(name=u'joe', email='*****@*****.**', title=u'Joe') send_set_password(user, DummyRequest(), templates=dict( subject=u"Hey there %(user_title)s", body=u"This is %(site_title)s speaking", )) assert self.mailer.send.called message = self.mailer.send.call_args[0][0] assert message.subject == 'Hey there Joe' assert message.body == 'This is Awesome site speaking'
def add_user_success(self, appstruct): appstruct.pop('csrf_token', None) _massage_groups_in(appstruct) name = appstruct['name'].lower() send_email = appstruct.pop('send_email', False) get_principals()[name] = appstruct if send_email: send_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): root = get_root(request) api = template_api(root, request) principals = get_principals() came_from = request.params.get('came_from', request.url) login, password = u'', u'' if 'submit' in request.POST: login = request.params['login'] 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, %s!" % 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: send_set_password(user, request, templates='reset-password') request.session.flash( u"You should receive an email with a link to reset your " u"password momentarily.", 'success') else: request.session.flash( "That username or email is not known to us.", 'error') return { 'api': api, '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'] 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: send_set_password(user, request, templates='reset-password') 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, }