def reg_invite_set_login(value): sess = env.user.session() if not sess.data(): env.user.session(reg_invite_set_login, key=value) return 'Please enter your nickname' if not sess['key']: env.user.session_destroy() return 'Fail' env.user.session_destroy() if value.startswith('@'): value = value[1:] if not validate_nickname(value): return xmpp_template('reg_invalid') try: users.register(login=value, accounts=[('xmpp', env.jid)]) redis = RedisPool(settings.storage_socket) redis.delete('invite:%s' % sess['key']) return xmpp_template('reg_ok', login=value) except UserExists: return 'User @%s already exists.' % value except UserError, e: log.error('%s: %s' % (e.__class__.__name__, e.message)) return e.message
def reg_steps(login=None, password=None): sess = env.user.session() if not sess.data(): env.user.session(reg_steps, login=login, password=password, val='123') return 'Type 123' text = login if text.strip() == sess['val']: env.user.session_destroy() users.register(sess['login'], password=sess['password'], accounts=[('xmpp', env.jid)]) return xmpp_template('reg_ok', login=sess['login']) else: env.user.session_destroy() return {'body': 'fail'}
def register(): #raise Forbidden if env.user.id: raise AlreadyAuthorized sess = Session() info = sess['reg_info'] or {} print 'INFO', info if env.request.method == 'GET': try: del info['network'] del info['uid'] except (KeyError, TypeError): pass sess['reg_info'] = info sess.save() try: info['birthdate'] = parse_date(info['birthdate']) \ or datetime.now() - timedelta(days=365*16+4) except (KeyError, TypeError): info['birthdate'] = None return render('/auth/register.html', fields=ULOGIN_FIELDS, info=info) try: network = info['network'] if 'network' in info else None uid = info['uid'] if 'uid' in info else None except TypeError: network = None uid = None errors = [] for p in [ 'login', 'name', 'email', 'birthdate', 'location', 'about', 'homepage' ]: info[p] = env.request.args(p, '').decode('utf-8') info['gender'] = _gender(env.request.args('gender')) login = env.request.args('login', '').strip() if login and validate_nickname(login): try: u = User('login', login) if u.id: errors.append('login-in-use') except UserNotFound: pass elif login: errors.append('login-invalid') else: errors.append('login-empty') password = env.request.args('password') confirm = env.request.args('confirm') if not (network and uid): if not password: errors.append('password') elif password != confirm: errors.append('confirm') info['birthdate'] = parse_date(info['birthdate']) \ or datetime.now() - timedelta(days=365*16+4) if not network and not errors: try: text = env.request.args('recaptcha_response_field') challenge = env.request.args('recaptcha_challenge_field') resp = captcha.submit(challenge, text, settings.recaptcha_private_key, env.request.remote_host) if not resp.is_valid: errors.append('captcha') except urllib2.URLError: errors.append('recaptcha-fail') except AddressNotFound: return Response(redirect='%s://%s/remember?fail=1' % \ (env.request.protocol, settings.domain)) if errors: if network and uid: tmpl = '/auth/register_ulogin.html' else: tmpl = '/auth/register.html' return render(tmpl, fields=ULOGIN_FIELDS, info=info, errors=errors) users.register(login) for p in [ 'name', 'email', 'birthdate', 'gender', 'location', 'about', 'homepage' ]: env.user.set_info(p, info[p]) if password: env.user.set_password(password) if network and uid: _nickname = info['_nickname'] if '_nickname' in info else None _name = info['_name'] if '_name' in info else None _profile = info['_profile'] if '_profile' in info else None try: env.user.bind_ulogin(network, uid, _nickname, _name, _profile) except UserExists: raise Forbidden if env.request.args('avatar'): ext = env.request.args('avatar', '').split('.').pop().lower() if ext not in ['jpg', 'gif', 'png']: errors.append('filetype') else: filename = ('%s.%s' % (env.user.login, ext)).lower() make_avatar(env.request.files('avatar'), filename) env.user.set_info('avatar', '%s?r=%d' % (filename, randint(1000, 9999))) elif 'avatar' in info and info['avatar']: filename = ('%s.%s' % (env.user.login, 'jpg')).lower() make_avatar(info['avatar'], filename) env.user.set_info('avatar', '%s?r=%d' % (filename, randint(1000, 9999))) env.user.save() env.user.authenticate() return Response(redirect=get_referer())
except urllib2.URLError, e: log.error('recaptcha fail: %s' % e) #errors.append('recaptcha-fail') except AddressNotFound: return Response(redirect='%s://%s/remember?fail=1' % \ (env.request.protocol, settings.domain)) if errors: if network and uid: tmpl = '/auth/register_ulogin.html' else: tmpl = '/auth/register.html' return render(tmpl, fields=ULOGIN_FIELDS, info=info, errors=errors) users.register(login) for p in ['name', 'email', 'birthdate', 'gender', 'location', 'about', 'homepage']: env.user.set_info(p, info[p]) if password: env.user.set_password(password) if network and uid: _nickname = info['_nickname'] if '_nickname' in info else None _name = info['_name'] if '_name' in info else None _profile = info['_profile'] if '_profile' in info else None try: env.user.bind_ulogin(network, uid, _nickname, _name, _profile) except UserExists: raise Forbidden
def register_post(): if env.user.id: raise AlreadyAuthorized sess = Session() info = sess["reg_info"] or {} try: del info["network"] del info["uid"] except (KeyError, TypeError): pass sess["reg_info"] = info sess.save() try: network = info["network"] if "network" in info else None uid = info["uid"] if "uid" in info else None except TypeError: network = None uid = None errors = [] for p in ["login", "name", "email", "birthdate", "location", "about", "homepage"]: info[p] = env.request.args(p, "").decode("utf-8") info["gender"] = _gender(env.request.args("gender")) login = env.request.args("login", "").strip() if login and validate_nickname(login): try: u = User("login", login) if u.id: errors.append("login-in-use") except UserNotFound: pass elif login: errors.append("login-invalid") else: errors.append("login-empty") password = env.request.args("password") if not (network and uid): if not password: errors.append("password") info["birthdate"] = parse_date(info["birthdate"]) if not network and not errors: try: resp = recaptcha2.verify( env.request.args("g-recaptcha-request", ""), settings.recaptcha_private_key, env.request.remote_host ) if not resp.is_valid: errors.append("captcha") except urllib2.URLError: errors.append("recaptcha-fail") except AddressNotFound: return Response(redirect="%s://%s/remember?fail=1" % (env.request.protocol, settings.domain)) if errors: if network and uid: tmpl = "/auth/register_ulogin.html" else: tmpl = "/auth/register.html" return Response(template=tmpl, fields=ULOGIN_FIELDS, info=info, errors=errors) users.register(login) for p in ["name", "email", "birthdate", "gender", "location", "about", "homepage"]: env.user.set_info(p, info[p]) if password: env.user.set_password(password) if network and uid: _nickname = info["_nickname"] if "_nickname" in info else None _name = info["_name"] if "_name" in info else None _profile = info["_profile"] if "_profile" in info else None try: env.user.bind_ulogin(network, uid, _nickname, _name, _profile) except UserExists: raise Forbidden if env.request.args("avatar"): ext = env.request.args("avatar", "").split(".").pop().lower() if ext not in ["jpg", "gif", "png"]: errors.append("filetype") else: filename = ("%s.%s" % (env.user.login, ext)).lower() make_avatar(env.request.files("avatar"), filename) env.user.set_info("avatar", "%s?r=%d" % (filename, randint(1000, 9999))) elif "avatar" in info and info["avatar"]: filename = ("%s.%s" % (env.user.login, "jpg")).lower() make_avatar(info["avatar"], filename) env.user.set_info("avatar", "%s?r=%d" % (filename, randint(1000, 9999))) env.user.save() env.user.authenticate() return Response(redirect=get_referer())
def register(): #raise Forbidden if env.user.id: raise AlreadyAuthorized sess = Session() info = sess['reg_info'] or {} print 'INFO', info if env.request.method == 'GET': try: del info['network'] del info['uid'] except (KeyError, TypeError): pass sess['reg_info'] = info sess.save() try: info['birthdate'] = parse_date(info['birthdate']) \ or datetime.now() - timedelta(days=365*16+4) except (KeyError, TypeError): info['birthdate'] = None return render('/auth/register.html', fields=ULOGIN_FIELDS, info=info) try: network = info['network'] if 'network' in info else None uid = info['uid'] if 'uid' in info else None except TypeError: network = None uid = None errors = [] for p in ['login', 'name', 'email', 'birthdate', 'location', 'about', 'homepage']: info[p] = env.request.args(p, '').decode('utf-8') info['gender'] = _gender(env.request.args('gender')) login = env.request.args('login', '').strip() if login and validate_nickname(login): try: u = User('login', login) if u.id: errors.append('login-in-use') except UserNotFound: pass elif login: errors.append('login-invalid') else: errors.append('login-empty') password = env.request.args('password') confirm = env.request.args('confirm') if not (network and uid): if not password: errors.append('password') elif password != confirm: errors.append('confirm') info['birthdate'] = parse_date(info['birthdate']) \ or datetime.now() - timedelta(days=365*16+4) if not network and not errors: try: text = env.request.args('recaptcha_response_field') challenge = env.request.args('recaptcha_challenge_field') resp = captcha.submit(challenge, text, settings.recaptcha_private_key, env.request.remote_host) if not resp.is_valid: errors.append('captcha') except urllib2.URLError: errors.append('recaptcha-fail') except AddressNotFound: return Response(redirect='%s://%s/remember?fail=1' % \ (env.request.protocol, settings.domain)) if errors: if network and uid: tmpl = '/auth/register_ulogin.html' else: tmpl = '/auth/register.html' return render(tmpl, fields=ULOGIN_FIELDS, info=info, errors=errors) users.register(login) for p in ['name', 'email', 'birthdate', 'gender', 'location', 'about', 'homepage']: env.user.set_info(p, info[p]) if password: env.user.set_password(password) if network and uid: _nickname = info['_nickname'] if '_nickname' in info else None _name = info['_name'] if '_name' in info else None _profile = info['_profile'] if '_profile' in info else None try: env.user.bind_ulogin(network, uid, _nickname, _name, _profile) except UserExists: raise Forbidden if env.request.args('avatar'): ext = env.request.args('avatar', '').split('.').pop().lower() if ext not in ['jpg', 'gif', 'png']: errors.append('filetype') else: filename = ('%s.%s' % (env.user.login, ext)).lower() make_avatar(env.request.files('avatar'), filename) env.user.set_info('avatar', '%s?r=%d' % (filename, randint(1000, 9999))) elif 'avatar' in info and info['avatar']: filename = ('%s.%s' % (env.user.login, 'jpg')).lower() make_avatar(info['avatar'], filename) env.user.set_info('avatar', '%s?r=%d' % (filename, randint(1000, 9999))) env.user.save() env.user.authenticate() return Response(redirect=get_referer())