示例#1
0
 def post(self):
     token = self.request.headers.get("Authorization")[len(PREFIX):]
     decoded = jwt.decode(token, SECRET, algorithms='HS256')
     if  decoded['role_id'] == '1':
         # add the user
         username = self.get_argument("username")  # maybe we can move these to __init__
         password = self.get_argument("password")
         group_id = self.get_argument("group_id")
         role_id = self.get_argument("role_id")
         database.create_account(username, password, group_id, role_id)
         self.write("%s user added successfully" % (username))
     else:
         self.write("role_id number %s is not authorised to register new users" % (decoded['role_id']))
示例#2
0
def register_page():
    
    if request.method == "POST":
        
        username = request.form["username"].strip()
        password = request.form["password"].strip()
        retyped_password = request.form["retypedPassword"].strip()

        if username == "" or password == "":
            message = "Can't create account with empty credentials"
            return render_template("register.html", message=message)

        if len(username) > 16 or len(username) < 3:
            message = "Username too short or too long"
            return render_template("register.html", message=message)

        if len(password) > 16 or len(password) < 6:
            message = "Password is too short or too long"
            return render_template("register.html", message=message)

        if password == retyped_password:
            if database.create_account(db, username, password):
                return redirect("/")
            else:
                message = "Username taken"
                return render_template("register.html", message=message)
        else:
            message = "Passwords didn't match"
            return render_template("register.html", message=message)
    else:
        message = ""
        return render_template("register.html", message=message)
示例#3
0
def account_post():
    result = ''
    if 'sign-up' in request.form:
        try:
            database.create_account(request.form.get('sign-up-user'),
                                    request.form.get('sign-up-password'))
            session.update(user=request.form.get('sign-up-user'))
            result = 'account created, logged in'
        except sqlite3.IntegrityError:
            result = 'nametaken'
    elif 'log-in' in request.form:
        if database.check_account(request.form.get('log-in-user'),
                                  request.form.get('log-in-password')):
            session.update(user=request.form.get('log-in-user'))
        else:
            result = 'loginfail'
    elif 'log-out' in request.form:
        session.clear()
        result = 'loggedout'
    return render_template('account.html', result=result)
示例#4
0
def create_account():
    name_input = input('\nEnter your name: ')

    names = db.get_account_names()
    if names is not None:
        if name_input in names:
            print('This username is already used.')
            create_account()

    password_input1 = stdiomask.getpass('Enter your password: '******'Repeat your password: '******'\nSuccessfully created an account.')
        prompt(name_input)
    else:
        cls()
        print('\nThe passwords are not matching.')
        prompt_auth()
示例#5
0
def register():
    print("\n\n######### Registration #########\n")

    firstname = input("Enter your first name\n")
    lastname = input("Enter your last name\n")
    email = input("Enter your email address\n")
    balance = input("Enter your starting account balance\n")

    # check if balance is a number (e.g. can be converted to float)
    if (is_valid_amount(balance)):
        password = getpass("Please enter your password\n")

        account_number = generateaccount_number()
        user_details = [firstname, lastname, email, password, balance]

        if (database.create_account(account_number, user_details)):
            print("\nCongratulation %s %s, your account has been created." %
                  (firstname, lastname))
            print("Your account number is %d" % (account_number))
            login()

    register()
示例#6
0
 def post(self):
     username = self.get_argument("username")
     password = self.get_argument("password")
     group_id = self.get_argument("group_id")
     role_id = self.get_argument("role_id")
     database.create_account(username, password, group_id, role_id)
示例#7
0
文件: main.py 项目: adnansalik/PUBank
import card as cd
import database as db
import menu as mn

db.create_account()


def stop():
    db.conn.close()
    print('Bye!')


def main_menu():
    while True:
        print(
            '\n1. Create an account\n2. Log into account\n3. Show all accounts\n0. Exit'
        )
        choice = input()
        if choice == '1':
            cd.create_card()
            continue
        elif choice == '2':
            loggedin = mn.login(cd.check_card())
            if loggedin:
                continue
            else:
                stop()
                break
        elif choice == '3':
            db.show_details()
        elif choice == '0':