def registrace(): form = RegistrationForm() if form.validate_on_submit(): if (form.password.data != form.passwordAgain.data): flash('Hesla nejsou stejná.', FlashStyle.Danger) email = session['confirmed_email'] form.email.data = email return render_template("registrace.html", form=form) email = session['confirmed_email'] form.email.data = email dbUser = DBUser() dbUser.email = form.email.data dbUser.password = form.password.data dbUser.level = 0 if DBAccess.ExecuteScalar('select id from users where email=%s', (dbUser.email, )) is not None: flash( f'Uživatel {dbUser.email} je již zaregistrován, zvolte jiný email.', FlashStyle.Danger) dbUser.email = None form.email.data = None return render_template("registrace.html", form=form) dbUser.salt = salt = DBAccess.ExecuteScalar("select salt()") #md% tranform password use md5 function on password + salt # md5Pass = hashlib.md5((dbUser.password+dbUser.salt).encode()).hexdigest() # dbUser.password = md5Pass bcrypt = Bcrypt() dbUser.password = bcrypt.generate_password_hash( dbUser.password).decode('UTF-8') dbUser.SaveToSession('dbUserRegistration') return redirect(url_for("login_bp.registrace_name")) #email = session.pop('confirmed_email',None) email = session.get('confirmed_email') if (email is None): abort(403) form.email.data = email return render_template("registrace.html", form=form)
def senior_registration(): form = SeniorRegistrationForm() if (form.validate_on_submit()): if form.password.data != form.passwordAgain.data: flash('Hesla nejsou totožná!', FlashStyle.Danger) return render_template('senior_registration.html', form=form) if DBAccess.ExecuteScalar( 'select id from users where trim(email) ilike %s', (form.email.data.strip(), )) is not None: flash( f'Uživatel {form.email.data} je již zaregistrován, zvolte jiný email.', FlashStyle.Danger) form.email.data = None return render_template('senior_registration.html', form=form) dbUser = DBUser() dbUser.first_name = form.first_name.data dbUser.surname = form.surname.data dbUser.email = form.email.data dbUser.telephone = form.telephone.data dbUser.telephone2 = form.telephone2.data dbUser.comment = form.comment.data dbUser.street = form.street.data dbUser.street_number = form.street_number.data if (form.street_number.data == ''): dbUser.street_number = 1 dbUser.town = form.town.data dbUser.post_code = form.post_code.data dbUser.password = form.password.data bcrypt = Bcrypt() dbUser.password = bcrypt.generate_password_hash( dbUser.password).decode('UTF-8') dbUser.level = 1 address = '{} {} {}'.format(dbUser.street, dbUser.town, dbUser.post_code) coordinates = GetCoordinates(address) if (coordinates is not None): dbUser.latitude = round(coordinates[0], 5) dbUser.longitude = round(coordinates[1], 5) x = 1 y = 1 difference = 0.00001 originalLatitude = dbUser.latitude originalLongitue = dbUser.longitude #check if same coordinates already exists while DBAccess.ExecuteScalar( 'select id from users where latitude=%s and longitude=%s', ( dbUser.latitude, dbUser.longitude, )) is not None: #if exists add difference and try again and again.. dbUser.latitude = originalLatitude + x * difference dbUser.longitude = originalLongitue + y * difference if x != -1: x -= 1 elif y != -1: y -= 1 else: x = 1 y = 1 difference += 0.00001 else: flash('Nenalezeny souřadnice pro vaši adresu', FlashStyle.Danger) return render_template('senior_registration.html', form=form) dbUser.salt = salt = DBAccess.ExecuteScalar("select salt()") dbUser.id = DBAccess.GetSequencerNextVal('users_id_seq') dbUser.InsertDB() flash( f'Senior {dbUser.first_name} {dbUser.surname} email: {dbUser.email} vložen do databáze a nastaven jako ověřený.', FlashStyle.Success) return redirect(url_for("login_bp.login")) return render_template('senior_registration.html', form=form)