def register(): form = RegistrationForm(request.form) if request.method == 'POST' and form.validate(): user_id = create_id() users_db[create_id()] = form.username.data return render_template("home.html") return render_template('registration.html', form=form)
def __init__(self, html_in=None, url=None): #!needs to take in html #words/phrases to check against that indicate that a field #is a certain type of field, we'll add to this as we add to #forms. This should be checked against field names and placeholders self.keywords_dic = { "email": ["user[email]", "email"], "email_confirmation": ["user[email_confirmation]"], "name": ["user[name]"], "password": ["user[password]"], "password_confirmation": ["user[password_confirmation]"], } self.html_in = html_in if not self.html_in: r = requests.get(url) self.html_in = r.text print self.html_in self.fe = FormExtractor.load() self.form = self._extract_forms_and_types(self.html_in) self.action = self.form.action self.inputs = self._get_inputs() self.filled_inputs = None self.filled_form = RegistrationForm()
def registration(er=None): form = RegistrationForm() if form.validate_on_submit(): users = UsersModel(db.get_connection()) users.insert( form.username.data, str(md5(bytes(form.password.data, encoding='utf-8')).hexdigest())) #add new user return redirect('/login') return render_template('registration.html', form=form, error=er)
def register(): if current_user.is_authenticated: return redirect(url_for('scoreboard')) form = RegistrationForm() if form.validate_on_submit(): user = create_user(form.username.data, form.email.data, form.password.data) user.save() flash('Congratulations, you are now a registered user!') login_user(user, remember=True) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('scoreboard') return redirect(next_page) return render_template('register.html', title='Register', form=form)
def register_view(self): form = RegistrationForm(request.form) if helpers.validate_form_on_submit(form): user = User() form.populate_obj(user) # we hash the users password to avoid saving it as plaintext in the db, # remove to use plain text: user.password = generate_password_hash(form.password.data) db.session.add(user) db.session.commit() login.login_user(user) return redirect(url_for('.index')) link = '<p>Already have an account? <a href="' + url_for('.login_view') + '">Click here to log in.</a></p>' self._template_args['form'] = form self._template_args['link'] = link return super(MyAdminIndexView, self).index()
def register_view(self): print("route-register-admin"); form = RegistrationForm(request.form) if helpers.validate_form_on_submit(form): Session = sessionmaker(bind=pg.obtem_engine()) session = Session() usuario = tables.Usuario() form.populate_obj(usuario) usuario.senha = generate_password_hash(form.senha.data) session.add(usuario) session.commit() login.login_user(usuario) return redirect(url_for('.index')) link = '<p>ja tem uma conta? <a href="' + url_for('.login_view') + '">acesse</a></p>' self._template_args['form'] = form self._template_args['link'] = link return super(MyAdminIndexView, self).index()
def registration(er=None): form = RegistrationForm() if form.validate_on_submit(): # if password, login, and photo is not empty users = UsersModel(db.get_connection()) if users.exists_only_by_name(form.username.data): return redirect( '/registration/exists' ) # if user is already in db you should do reregistration else: users.insert( form.username.data, str( md5(bytes(form.password.data, encoding='utf-8')).hexdigest( ))) # add to db hash of the password for better encryption form.fileName.data.save( os.path.join(os.path.join('static', 'avas'), str(users.get_table_size()) + ".jpg")) return redirect('/login') return render_template('registration.html', form=form, error=er)
def registration(er=None): form = RegistrationForm() if form.validate_on_submit(): users = UsersModel(db.get_connection()) udm = UserDataModel(db.get_connection()) find = users.find(form.username.data) if find[0]: return redirect('/registration/exists') else: if form.username.data == 'admin': users.insert(form.username.data, form.password.data, 'admin') else: users.insert(form.username.data, form.password.data, 'user') # add new user udm.insert(form.username.data, 'Фамилия', 'Имя', 'Отчество', 'Адрес', 'Номер счетчика') return redirect('/login') return render_template('registration.html', form=form, error=er, text="Авторизоваться")
def registration(): # Форма регистрации form = RegistrationForm() # POST if form.validate_on_submit(): # Проверка паролей на совпадение if form.password.data != form.password_again.data: return render_template('registration.html', form=form, message='Пароли не совпадают!') # Создаём сессию подключения к БД session = db_session.create_session() # Проверка почты на уникальность if session.query(Users).filter(Users.email == form.email.data).first(): return render_template( 'registration.html', form=form, message='Пользователь с такой почтой уже существует!') # Проверка логина на уникальность if session.query(Users).filter(Users.login == form.login.data).first(): return render_template( 'registration.html', form=form, message='Пользователь с таким логином уже существует!') # Добавление пользователя в БД user = Users(login=form.login.data, email=form.email.data) # Генерация хешированного пароля user.generate_hashed_password(form.password.data) session.add(user) # Сохранение пользователя session.commit() # Перенаправление на страницу входа return redirect('/login') return render_template('registration.html', form=form)
class RegistrationFormFiller(object): def __init__(self, html_in=None, url=None): #!needs to take in html #words/phrases to check against that indicate that a field #is a certain type of field, we'll add to this as we add to #forms. This should be checked against field names and placeholders self.keywords_dic = { "email": ["user[email]", "email"], "email_confirmation": ["user[email_confirmation]"], "name": ["user[name]"], "password": ["user[password]"], "password_confirmation": ["user[password_confirmation]"], } self.html_in = html_in if not self.html_in: r = requests.get(url) self.html_in = r.text print self.html_in self.fe = FormExtractor.load() self.form = self._extract_forms_and_types(self.html_in) self.action = self.form.action self.inputs = self._get_inputs() self.filled_inputs = None self.filled_form = RegistrationForm() def _extract_forms_and_types(self, html_in): self.tree = lxml.html.fromstring(html_in) form = self.fe.extract_forms(self.tree) return form[0][0] def _get_inputs(self): input_dics = [] self.some_tree = self.tree.getroottree() for child in self.form.xpath("//input"): input_dic = {} for k, v in child.items(): input_dic[k] = v #get xpath input_xpath = self.some_tree.getpath(child) input_dic["xpath"] = input_xpath input_dics.append(input_dic) return input_dics def _normalize_field_value(self, value): if value.strip() == "": return None if value.strip(): return value.strip() def _detect_input_types(self): forms_with_type = [] for input in self.inputs: filled_input_and_type = {} if "name" in input: detected_type = self._find_in_keywords_dic(input["name"]) input["detected_type"] = detected_type forms_with_type.append(input) #will produce duplicates for input in self.inputs: filled_input_and_type = {} if "detected_type" not in input and "placeholder" in input: detected_type = self._find_in_keywords_dic( input["placeholder"]) input["detected_type"] = detected_type forms_with_type.append(input) self.forms_with_type = forms_with_type print self.forms_with_type return forms_with_type def _find_in_keywords_dic(self, name_or_placeholder): #search through the keywords_dic for name_or_placeholder #in the keywords_dic, if it's found in one of the lists #of words return the list it was found in (email, email # confirmation, etc) for k, v in self.keywords_dic.iteritems(): if name_or_placeholder in v: return k return None def prepare_registration_form(self): for input in self.inputs: field_name = input["name"] if "value" in input: field_value = input["value"] else: field_value = None self.filled_form.add_attribute(field_name, field_value) return self.filled_form.attribute_dict def fill_form(self): self._detect_input_types() filled_inputs = [] for input in self.forms_with_type: if "detected_type" in input: if input["detected_type"] == "email": input["value"] = "*****@*****.**" if input["detected_type"] == "email_confirmation": input["value"] = "*****@*****.**" if input["detected_type"] == "name": input["value"] = "Random Name" if input["detected_type"] == "password": input["value"] = "r@nd0mP@ssw0rd" if input["detected_type"] == "password_confirmation": input["value"] = "r@nd0mP@ssw0rd" filled_inputs.append(input) return filled_inputs