예제 #1
0
def login():
    form = user_login()
    Error_ = ""
    if request.method == 'POST':
        try:
            email_ = form.email.data
            password = form.password.data
            if len(email_) == 0 and len(password) == 0:
                return render_template('login.html', form=form,
                                       Error_=3)  #no input
            else:
                print('here input' + email_)
                res = api.login(
                    email_, password
                )  #json.loads((requests.get('{}/login/{}/{}'.format(host_address,email_, password))).text)
                present = res['status']
                if present:
                    session['uid'] = res['user_id']
                    session['username'] = res['username']
                    user = User()
                    user.id = email_
                    print(flask_login.current_user.is_authenticated)
                    flask_login.login_user(user)
                    return redirect(url_for('users.index'))
                Error_ = 1  # not valid
                return render_template('login.html', form=form, Error_=Error_)
        except KeyError:
            Error_ = 2  # 'ERROR_ON_USER_KEY'
        except Exception as e:
            Error_ = 'ok' + str(e)
    print(Error_)
    if flask_login.current_user.is_authenticated:
        return redirect(url_for('users.index'))
    else:
        return render_template('login.html', form=form, Error_=Error_)
예제 #2
0
def createuser(email=None, password=None, role=None):
    """Create a user"""

    if not email:
        email = prompt("A valid email address")

    if not password:
        password = prompt_pass("Password")

    if not role:
        roles = [r.name for r in db.session.query(Role)]
        role_name = prompt_choices("Role",
                                   choices=roles,
                                   no_choice=('none', ''))
        if role_name:
            role = get_or_create(db.session, Role, name=role_name)
        else:
            role = None
    else:
        role = get_or_create(db.session, Role, name=role)

    if all([email, password]):
        user = User.createuser(db.session, email, password, roles=[role])
        db.session.commit()
    else:
        user = "******"

    print(user)
예제 #3
0
def createuser(email=None, password=None, role=None):
    """Create a user"""

    if not email:
        email = prompt("A valid email address")

    if not password:
        password = prompt_pass("Password")

    if not role:
        roles = [r.name for r in db.session.query(Role)]
        role_name = prompt_choices("Role", choices=roles,
                                   no_choice=('none', ''))
        if role_name:
            role = get_or_create(db.session, Role, name=role_name)
        else:
            role = None
    else:
        role = get_or_create(db.session, Role, name=role)

    if all([email, password]):
        user = User.createuser(db.session, email, password, roles=[role])
        db.session.commit()
    else:
        user = "******"

    print(user)
예제 #4
0
def save_new_user(newUser, newEmail, newPassword):
    user = User(nome=newUser,
                email=newEmail,
                senha=guard.hash_password(newPassword))

    db.session.add(user)
    db.session.commit()
예제 #5
0
def createsuperuser(email=None, password=None):
    """Create a supersuer"""

    if not email:
        email = prompt("A valid email address")

    if not password:
        password = prompt_pass("Password")

    if all([email, password]):
        admin = get_or_create(db.session, Role, name='admin')
        user = User.createuser(db.session, email, password, roles=[admin])
        db.session.commit()
    else:
        user = "******"

    print(user)
예제 #6
0
def createsuperuser(email=None, password=None):
    """Create a supersuer"""

    if not email:
        email = prompt("A valid email address")

    if not password:
        password = prompt_pass("Password")

    if all([email, password]):
        admin = get_or_create(db.session, Role, name='admin')
        user = User.createuser(db.session, email, password, roles=[admin])
        db.session.commit()
    else:
        user = "******"

    print(user)
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
예제 #9
0
from project import db, User

# s1 = User(first_name='Tyrion', last_name='Lannister', username='******', email='*****@*****.**', location='Westeros', bio='Still going strong', password='******')
s2 = User(first_name='Jamie',
          last_name='Lannister',
          username='******',
          email='*****@*****.**',
          location='Westeros',
          bio='What am I even doing anymore',
          password='******')

# db.session.add(s1)
db.session.add(s2)

db.session.commit()
예제 #10
0
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
예제 #11
0
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
예제 #13
0
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
예제 #14
0
파일: manage.py 프로젝트: Anushav11/flask
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
예제 #15
0
파일: manage.py 프로젝트: yaminiu/k8s
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
예제 #16
0
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
예제 #17
0
def seed_db():
    db.session.add(User(email='*****@*****.**'))
    db.session.commit()
예제 #18
0
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
예제 #19
0
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
class Main:
    # keep track of all the accounts
    accounts = []
    print("Welcome to New Age Banking")

    # User 1 prompts
    print("Hello User 1! Let's get started, please follow the instructions bellow - ")
    user1_username = input("Enter a username: "******"Enter your initial deposit: [only enter NUMBERS] ")
    user1 = User.User(user1_username, int(user1_investment))
    accounts.append(user1)

    # User 2 prompts
    print("Hello User 2! Let's get started, please follow the instructions bellow - ")
    user2_username = input("Enter a username: "******"Enter your initial deposit: [only enter NUMBERS] ")
    user2 = User.User(user2_username, int(user2_investment))
    accounts.append(user2)
    # False: if session is active True: session inactive
    session_status = False

    # Creating the BlockChain
    transactionChain = Transactions.TransactionChain()

    while not session_status:
        # Finding the sending user from array of users, we could use hashtable for O(1) lookup speed
        # sending_user = None

        chosen_user = input("Please enter your username: "******"Who are you working with? ")
        if chosen_user != chosen_destination:
            for i in accounts:
                if chosen_destination == i.get_username():
                    selected_destination_number = i.get_line_number()

        transaction_selection = input("What would you like to do? Send[0] Request[1] ")
        # Chose to send money
        if transaction_selection == "0":
            send_amount = input("How much do you want to send? [only enter NUMBERS] ")
            # Checks if input is a number
            if int(send_amount):
                # Checks account balance
                if accounts[selected_number].check_balance(send_amount) == 1:
                    # Creates Transaction ID
                    current_transaction_id = str(accounts[selected_number].get_username()) + str(send_amount) + str(
                        accounts[selected_destination_number].get_username())
                    # Creates Transaction Block
                    print(current_transaction_id)
                    transaction = Transactions.Transaction(str(current_transaction_id))
                    print("Approval pending...")
                    # adds Block to Chain
                    transactionChain.mine(transaction)
                    # Checks if it has been added
                    if transaction.get_approval() == 1:
                        print("Transaction as been approved!")
                        # Sends money
                        accounts[selected_destination_number].receive_money(accounts[selected_number].send_money(send_amount))
                        # Update on the balances
                        for i in accounts:
                            print(str(i.get_username()) + ": Balance = " + str(i.get_balance()))
                    else:
                        print("Your transaction was not approved!")
                else:
                    print("Not enough money in your account!")

        # Chose to request money
        elif transaction_selection == "1":
            request_amount = input("How much do you want to request ")
            # Checks if input is a number
            if int(request_amount):
                # Checks for approval of other User
                dst_approval = input(accounts[selected_destination_number].get_username() + ", Do you agree? [Y/N]")
                # Clears Approvals
                if dst_approval == "Y":
                    # Checks account balance
                    if accounts[selected_destination_number].check_balance(request_amount) == 1:
                        # Creates Transaction ID
                        current_transaction_id = str(accounts[selected_number].get_username()) + str(
                            request_amount) + str(accounts[selected_destination_number].get_username())
                        # Creates Transaction Block
                        transaction = Transactions.Transaction(str(current_transaction_id))
                        print("Approval pending...")
                        # Adds to Chain
                        transactionChain.mine(transaction)
                        # Checks if it has been added
                        if transaction.get_approval() == 1:
                            print("Transaction as been approved!")
                            # Sends money
                            accounts[selected_number].receive_money(accounts[selected_destination_number].send_money(request_amount))
                            # Checks balances
                            for i in accounts:
                                print(str(i.get_username()) + ": Balance = " + str(i.get_balance()))
                        else:
                            print("Your transaction was not approved!")
                    else:
                        print("Not enough money in your account!")
                else:
                    print("Your transaction was not approved!")

        # Allows the program to continue or stop
        status = input("Is that all for this session? [Y/N] ")
        if status == "Y":
            session_status = True
            print("Thank you for working with New Age Banking, come back soon!")
            print("---------------------------------------")
            print("Here are your chains:")
            # Runs through/displays Sending Chain
            print("Transaction Chain: ")
            while transactionChain.head is not None:
                print(transactionChain.head)
                transactionChain.head = transactionChain.head.next
            # Runs through/displays Request Chain
        else:
            session_status = False
예제 #21
0
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
예제 #22
0
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
예제 #23
0
def seed_db():
    user = User(email='user01@email')
    user.active = False
    db.session.add(user)
    db.session.commit()
예제 #24
0
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
예제 #25
0
def seed_db():
    db.session.add(User(email="*****@*****.**"))
    db.session.commit()
예제 #26
0
def seed_db():
    db.session.add(User(email='*****@*****.**'))
    db.session.commit()