def test(): ''' Directly, URL don't open any page. That's intermediate URL for processing data, reveived from HTML-forms ''' try: variables.my_email_error[0], variables.my_password_error[ 0] = None, None if current_user.is_authenticated: return redirect(url_for('render_table')) form = register_form() if form.validate_on_submit(): password = hash.hashing(register_form().password.data) email = register_form().email.data user_info_to_db = users(email=register_form().email.data, user_password=password) db.session.add(user_info_to_db) db.session.commit() email = users.query.filter_by(email=form.email.data).first() login_user(email, remember=register_form().remember.data) flash(f'accounted created for {register_form().email.data}') return redirect(url_for('tg_autentification')) # put errors in variables. That's not "musthave", but it's more comfortable in my case for me if form.email.errors: for error in form.email.errors: variables.my_email_error[0] = error if form.password.errors: for error in form.password.errors: variables.my_password_error[0] = error # have finished to put return redirect(url_for('errors')) except Exception as ex: config_file.ex_catcher(current_user.id, "test", ex) return redirect(url_for('dope_shit', ex=ex))
def post(self): f = register_form() captcha_html = captcha.displayhtml(self.settings.CAPTCHA_PUBLIC_KEY, True) captcha_error = '' data = self.get_arguments() _ = self._ if False and data.has_key('username'): existing_user = User.one({'username': data['username']}) f.add_notnull_validator(not existing_user, "The username you wanted is already taken.") try: if f.validates(Storage(data)): #todo use async call captcha_resp = captcha.submit( self.get_argument('recaptcha_challenge_field'), self.get_argument('recaptcha_response_field'), self.settings.CAPTCHA_PRIVATE_KEY, self.request.remote_ip ) if captcha_resp.is_valid: new_user = User() data['is_admin'] = False data['password_hashed'] = unicode(hashlib.sha1(data['password']).hexdigest(), 'utf-8') data['auth_provider'] = u'form' new_user.save(data) self.set_flash(_("You have been successfully registered. ")) self.redirect("/") return captcha_error = captcha_resp.error_code raise Exception("Invalid captcha code") raise InvalidFormDataError(_("Form still have errors.")) except Exception, e: f.note = f.note if f.note else e self.render("register", f=f, captcha_html=captcha_html, captcha_error=captcha_error)
def get(self): f = register_form() captcha_html = captcha.displayhtml(self.settings.CAPTCHA_PUBLIC_KEY, True) self.render("register", f=f, captcha_html=captcha_html, captcha_error='')
def errors(): '''URL for registrations''' try: if current_user.is_authenticated: return redirect(url_for('render_table')) form = register_form() return render_template('login/registrate.html', form=form, my_email_error=variables.my_email_error, my_password_error=variables.my_password_error) except Exception as ex: config_file.ex_catcher(current_user.id, "errors", ex) return redirect(url_for('dope_shit', ex=ex))
def register(): from forms import register_form form = register_form(request.form) if request.method == 'POST' and form.validate(): user = User() form.populate_obj(user) user.set_password(form.password.data) db.session.add(user) db.session.commit() login_user(user) return redirect(url_for('index')) return render_template('register.html', form=form)
def create_login(): from forms import register_form form = register_form(request.form) if request.method == 'POST' and form.validate(): user = User() form.populate_obj(user) user.set_password(form.password.data) db.session.add(user) db.session.commit() login_user(user) return redirect(url_for('index')) return render_template("reg.html", form=form)
def register(request): """User registration view""" if request.method == 'POST': form = register_form(request.POST) if form.is_valid(): user = User.objects.create_user( username=form.cleaned_data['username'], password=form.cleaned_data['password'], email=form.cleaned_data['email'], ) user.save() return HttpResponse('dupka') elif request.method == 'GET': return render(request, 'register.html')
def POST(self): form = register_form() if form.validates(): hashed_password, salt = hash_password(form['password'].value) # TODO: replace hardcoded privilege privilege = 1 db.insert('example_users', username=form['username'].value, email=form['email'].value, privilege=privilege, hashed_password=hashed_password, salt=salt) seeother('/login') else: return render.register(form)
def __init__( self, questionFile, enableMathJax=True, registerAll=False, adminIP='127.0.0.1', monitorClass=TrivialMonitor, mathJaxPath='/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML', configPath='cp.conf', rootPath='', shutdownFunc=None, **kwargs): if configPath: self.app = cherrypy.tree.mount(self, '/', configPath) try: cherrypy.config.update(self.app.config['global']) except KeyError: pass self.enableMathJax = enableMathJax if enableMathJax: if configPath and mathJaxPath is not None and \ mathJaxPath.startswith('/') and \ not check_static_path(self.app.config, mathJaxPath): warnings.warn('''mathJaxPath %s not accessible. Check config. Falling back to MathJax CDN...''' % mathJaxPath) mathJaxPath = None if mathJaxPath is None: # fallback to MathJax CDN mathJaxPath = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' webui.Document._defaultHeader = '''<script type="text/javascript" src="%s"> </script> ''' % mathJaxPath self.adminIP = adminIP self.root = rootPath self.shutdownFunc = shutdownFunc self.courseDB = CourseDB(questionFile, enableMath=enableMathJax, **kwargs) self._registerHTML = forms.register_form() self.registerAll = registerAll self._loginHTML = forms.login_form() self._reloadHTML = redirect(rootPath + '/index') self.questions = {} if questionFile: self.serve_question(self.courseDB.questions[0]) self.monitor = monitorClass()
def register(): form = register_form(request.form) if request.method == "POST": if form.validate(): mobile = form.mobile.data email = form.email.data name = form.name.data username = form.username.data password = sha256_crypt.encrypt((str(form.password.data))) role = form.role.data c, conn = cursor_conn() x = c.execute("SELECT * FROM FLASKAPP.users WHERE username = (%s)", (thwart(username))) if int(x) > 0: flash("That username is already taken, please choose another") return render_template('register.html', form=form) else: try: c.execute( "INSERT INTO FLASKAPP.users (email, password, name, mobile, role, username) VALUES (%s, %s, %s, %s, %s, %s)", (thwart(email), thwart(password), thwart(name), thwart(mobile), thwart(role), thwart(username))) flash("Thanks for registering!") except: flash( "That Mobile number is already taken, please choose another" ) return render_template('register.html', form=form) c.close() conn.close() gc.collect() session['logged_in'] = role session['username'] = username return render_template('main.html') else: flash("Error in form. Please Fill Again") return render_template('register.html', form=form)
def post(self): f = register_form() captcha_html = captcha.displayhtml(self.settings.CAPTCHA_PUBLIC_KEY, True) captcha_error = '' data = self.get_arguments() _ = self._ if False and data.has_key('username'): existing_user = User.one({'username': data['username']}) f.add_notnull_validator( not existing_user, "The username you wanted is already taken.") try: if f.validates(Storage(data)): #todo use async call captcha_resp = captcha.submit( self.get_argument('recaptcha_challenge_field'), self.get_argument('recaptcha_response_field'), self.settings.CAPTCHA_PRIVATE_KEY, self.request.remote_ip) if captcha_resp.is_valid: new_user = User() data['is_admin'] = False data['password_hashed'] = unicode( hashlib.sha1(data['password']).hexdigest(), 'utf-8') data['auth_provider'] = u'form' new_user.save(data) self.set_flash( _("You have been successfully registered. ")) self.redirect("/") return captcha_error = captcha_resp.error_code raise Exception("Invalid captcha code") raise InvalidFormDataError(_("Form still have errors.")) except Exception, e: f.note = f.note if f.note else e self.render("register", f=f, captcha_html=captcha_html, captcha_error=captcha_error)
def __init__(self, questionFile, enableMathJax=True, registerAll=False, adminIP='127.0.0.1', monitorClass=TrivialMonitor, mathJaxPath='/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML', configPath='cp.conf', rootPath='', shutdownFunc=None, **kwargs): if configPath: self.app = cherrypy.tree.mount(self, '/', configPath) try: cherrypy.config.update(self.app.config['global']) except KeyError: pass self.enableMathJax = enableMathJax if enableMathJax: if configPath and mathJaxPath is not None and \ mathJaxPath.startswith('/') and \ not check_static_path(self.app.config, mathJaxPath): warnings.warn('''mathJaxPath %s not accessible. Check config. Falling back to MathJax CDN...''' % mathJaxPath) mathJaxPath = None if mathJaxPath is None: # fallback to MathJax CDN mathJaxPath = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' webui.Document._defaultHeader = '''<script type="text/javascript" src="%s"> </script> ''' % mathJaxPath self.adminIP = adminIP self.root = rootPath self.shutdownFunc = shutdownFunc self.courseDB = CourseDB(questionFile, enableMath=enableMathJax, **kwargs) self._registerHTML = forms.register_form() self.registerAll = registerAll self._loginHTML = forms.login_form() self._reloadHTML = redirect(rootPath + '/index') self.questions = {} if questionFile: self.serve_question(self.courseDB.questions[0]) self.monitor = monitorClass()
def GET(self): # 1. call form to create copy, 2. pass form to template form = register_form() return render.register(form)