Beispiel #1
0
def regOfficial():
    if request.method == 'POST':
        name = request.form['name']
        unit = request.form['unit']
        email = request.form['email']
        type = request.form['type']
        grade = request.form['grade']
        password = request.form['password']
        app.logger.info(type)
        secret = str(uuid4()).replace("-", "")[0:6]
        password = sha256_crypt.hash(password)
        keyGen(username=email, type=type)
        officialId = generateWalletAddr(username=email, type=type)
        cursor = mysql.connection.cursor()
        query = "INSERT INTO officials(officialId, name, unit, email, password, secret, type, grade) VALUES('" + officialId + "', '" + name + "', '" + unit + "', '" + email + "', '" + password + "', '" + secret + "', '" + type + "', '" + grade + "');"
        app.logger.info(query)
        cursor.execute(query)
        mysql.connection.commit()

        publicKey = getPublicKey(username=email, type=type).decode('utf-8')
        query = 'INSERT INTO userKeys(userid,type,publicKey) VALUES ( "' + officialId + '","' + type + '","' + publicKey + '");'
        app.logger.info(query)
        result = cursor.execute(query)
        mysql.connection.commit()

        cursor.close()
        return render_template('admin/register.html')
    return render_template('admin/register.html')
Beispiel #2
0
def registerUser():
    if request.method == 'POST':
        name = request.form['fname']
        username = request.form['uname']
        password = request.form['pwd']
        password = sha256_crypt.hash(password)
        #confirm = request.form['cpwd']

        #generate wallet address UUID
        _ = keyGen(username=username, type='user')
        userid = generateWalletAddr(username=username, type='user')
        cursor = mysql.connection.cursor()
        query = 'INSERT INTO users(userid,username,name, password) VALUES ( "' + userid + '","' + username + '","' + name + '","' + password + '");'
        app.logger.info(query)
        result = cursor.execute(query)
        mysql.connection.commit()
        type = 'user'
        publicKey = getPublicKey(username=username,
                                 type='user').decode('utf-8')
        query = 'INSERT INTO userKeys(userid,type,publicKey) VALUES ( "' + userid + '","' + type + '","' + publicKey + '");'
        app.logger.info(query)
        result = cursor.execute(query)
        mysql.connection.commit()
        cursor.close()
        if result:
            return redirect(url_for('userLogin'))
        return render_template('user/signup.html')
    return render_template('user/signup.html')
Beispiel #3
0
def officialSettings():
    if request.method == "POST":
        checker = request.form['checker']
        app.logger.info(checker)
        if checker == "changePwd":
            password = request.form['opassword']
            newPassord = request.form['npassword']
            confirm = request.form['cpassword']
            if newPassord == confirm:
                cursor = mysql.connection.cursor()
                query = "SELECT password FROM officials where email = '" + session[
                    'email'] + "';"
                app.logger.info(query)
                cursor.execute(query)
                record = cursor.fetchone()
                hash = record['password']
                app.logger.info(hash)
                app.logger.info(sha256_crypt.hash(password))
                if sha256_crypt.verify(password, hash):
                    query = "UPDATE officials SET password ='******' WHERE email = '" + session['email'] + "';"
                    cursor.execute(query)
                    mysql.connection.commit()
                    cursor.close()
        elif checker == "changeKey":
            query = "UPDATE userKeys SET deprication ='" + datetime.now(
            ).isoformat().split('T')[0] + "' WHERE userid = '" + session[
                'officialId'] + "' and deprication = 'NULL';"
            app.logger.info(query)
            cursor = mysql.connection.cursor()
            cursor.execute(query)
            mysql.connection.commit()
            type = "official"
            _ = keyGen(username=session['username'], type=type)
            publicKey = getPublicKey(username=session['username'],
                                     type=type).decode('utf-8')
            query = 'INSERT INTO userKeys(userid,type,publicKey) VALUES ( "' + session[
                "officialId"] + '","' + type + '","' + publicKey + '");'
            app.logger.info(query)
            cursor.execute(query)
            mysql.connection.commit()
            cursor.close()
        elif checker == '2FA':
            email = request.form['email']
            phone = request.form['number']
            query = "INSERT INTO settings(userid, phone, email, temporaryCode) VALUES('" + session[
                'officialId'] + "' , '" + phone + "' , '" + email + "' , '" + str(
                    uuid4()).replace("-", "")[0:6] + "');"
            app.logger.info(query)
            cursor = mysql.connection.cursor()
            cursor.execute(query)
            mysql.connection.commit()
            cursor.close()
        else:
            pass
        return render_template('official/settings.html')
    return render_template('official/settings.html')