def insert_user(form): try: check_user = User.query(User.email == form.email.data).fetch(1) if check_user > 0: u = User() u.uuid = str(uuid.uuid4()) u.nome = form.nome.data u.cognome = form.cognome.data u.password = hashlib.sha1(form.password.data).hexdigest() u.email = form.email.data # insert tariffa tariffe = Tariffa.query(Tariffa.visibilita == True).order( Tariffa.order).fetch() for i, tar in enumerate(tariffe): if (i + 1) == int(form.tariffa.data): u.tariffa = tar.tariffa u.targa = form.targa.data u.put() return True return False except: return False
def password(): if request.method == 'GET': form = ModPw() return render_template('user/modifica_password.html', form=form, user=get_username(session)) elif request.method == 'POST': try: pw = request.form['password'] # modifica password nel database user = User.query(User.uuid == session['user']['user_id']).fetch(1)[0] user.password = hashlib.sha1(pw).hexdigest() user.put() # logout flash("Modifica password avvenuta correttamente.") return redirect(url_for('auth.logout')) except: flash("Erroe nella modifica. Riprova piu' tardi.") return redirect(url_for('main.index'))
def login_user(form): try: user_data = User.query( User.email == form.email.data, User.password == hashlib.sha1( form.password.data).hexdigest()).fetch(1) if len(user_data) > 0: session['user'] = { "user_id": str(user_data[0].uuid), "nome": user_data[0].nome, "cognome": user_data[0].cognome, "email": user_data[0].email, "superuser": user_data[0].has_superuser, "active": user_data[0].is_valid, "authenticated": user_data[0].is_authenticated } return session['user']['authenticated'] else: return False except: return False