Commit 142a7a6a authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

3.6 api update and other cleanups

parent 4d32b157ca2d
/* template specific CSS */
div#loginContent a {
color:black;
}
color: black;
text-align: center;
}
div#loginContent a:hover {
color:gray;
}
\ No newline at end of file
color: gray;
}
\ No newline at end of file
......@@ -14,12 +14,12 @@ from yams import ValidationError
from logilab.mtconverter import xml_escape
from cubicweb.view import StartupView
from cubicweb.web import (Redirect, controller, form, formwidgets as wdg,
formfields as ff)
from cubicweb.web.views import forms, urlrewrite, basetemplates
from cubicweb.view import StartupView
from cubicweb.server.repository import Repository
# XXX move to cw to avoid dependancy
from cubes.registration.views import CaptchaWidget, encrypt, decrypt
_ = unicode
......@@ -27,13 +27,14 @@ _ = unicode
# Login form
# ----------
class LogFormTemplateForgotPassword(basetemplates.LogFormTemplate):
class LogFormView(basetemplates.LogFormView):
def login_form(self, id):
super(LogFormTemplateForgotPassword, self).login_form(id)
super(LogFormView, self).login_form(id)
self._cw.add_css('cubes.forgotpwd.css')
self.w(u'<p style="text-align:center"><a href="%s">%s</a></p>' % (
self.build_url('forgottenpassword'), self._cw._('Forgot your password ?')))
self.w(u'<p><a href="%s">%s</a></p>' % (
xml_escape(self._cw.build_url('forgottenpassword')),
self._cw._('Forgot your password ?')))
# First form, send an email
# -------------------------
......@@ -55,7 +56,7 @@ class ForgottenPasswordFormView(form.FormViewMixIn, StartupView):
__regid__ = 'forgottenpassword'
def call(self):
form = self.vreg['forms'].select('forgottenpassword', self._cw)
form = self._cw.vreg['forms'].select('forgottenpassword', self._cw)
self.w(u'<p>%s</p>' % self._cw._(u'Forgot your password ?'))
self.w(form.render())
......@@ -78,7 +79,7 @@ class ForgottenPasswordSendMailController(controller.Controller):
'''only basic data check here (required attributes and password
confirmation check)
'''
fieldsform = self.vreg['forms'].select('forgottenpassword', self._cw)
fieldsform = self._cw.vreg['forms'].select('forgottenpassword', self._cw)
data = {}
errors = {}
for field in fieldsform._fields_:
......@@ -122,19 +123,20 @@ class ForgottenPasswordRequestView(form.FormViewMixIn, StartupView):
def check_key(self):
try:
return decrypt(self._cw.form['key'], self.vreg.config['cypher-seed'])
return decrypt(self._cw.form['key'], self._cw.vreg.config['cypher-seed'])
except:
msg = self._cw._(u'Invalid link. Please try again.')
raise Redirect(self._cw.build_url(u'forgottenpassword', __message=msg))
def call(self):
key = self.check_key()
form = self.vreg['forms'].select('forgottenpasswordrequest', self._cw)
form.form_add_hidden('use_email', key['use_email'])
form.form_add_hidden('revocation_id', key['revocation_id'])
form = self._cw.vreg['forms'].select('forgottenpasswordrequest', self._cw)
form.add_hidden('use_email', key['use_email'])
form.add_hidden('revocation_id', key['revocation_id'])
self.w(u'<p>%s</p>' % self._cw._(u'Update your password:'))
self.w(form.render())
class ForgottenPasswordRequestConfirm(controller.Controller):
__regid__ = 'forgottenpassword-requestconfirm'
......@@ -144,18 +146,18 @@ class ForgottenPasswordRequestConfirm(controller.Controller):
raise Redirect(self.build_url('pwdreset', __message=msg))
def checked_data(self):
fieldsform = self.vreg['forms'].select('forgottenpasswordrequest', self._cw)
cw = self._cw
fieldsform = cw.vreg['forms'].select('forgottenpasswordrequest', cw)
data = {}
errors = {}
for field in fieldsform._fields_:
value = self._cw.form.get(field.name, u'').strip()
if not value:
if field.required:
errors[field.name] = self._cw._('required attribute')
for field in fieldsform.fields:
value = cw.form.get(field.name, u'').strip()
if not value and field.required:
errors[field.name] = cw._('required attribute')
data[field.name] = value
data['use_email'] = self._cw.form.get('use_email', '').strip()
data['revocation_id'] = self._cw.form.get('revocation_id', '').strip()
if data['upassword'] != self._cw.form.get('upassword-confirm'):
data['use_email'] = cw.form.get('use_email', '').strip()
data['revocation_id'] = cw.form.get('revocation_id', '').strip()
if data['upassword'] != cw.form.get('upassword-confirm'):
errors['upassword'] = _('passwords are different')
if errors:
raise ValidationError(None, errors)
......@@ -227,14 +229,6 @@ def forgotpwd_change_passwd(self, data):
finally:
session.close()
# Registration
# ------------
def registration_callback(vreg):
vreg.register_all(globals().values(), __name__, (LogFormTemplateForgotPassword,))
vreg.register_and_replace(LogFormTemplateForgotPassword,
basetemplates.LogFormTemplate)
# URL rewriting
# -------------
......@@ -245,3 +239,10 @@ class RegistrationSimpleReqRewriter(urlrewrite.SimpleReqRewriter):
('/pwdsent', dict(vid='pwdsent')),
('/pwdreset', dict(vid='pwdreset')),
]
# Registration
# ------------
def registration_callback(vreg):
vreg.register_all(globals().values(), __name__, (LogFormView,))
vreg.register_and_replace(LogFormView, basetemplates.LogFormView)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment