1. 로그인 화면에서의 register 버튼 활성화

<a href="{{ url_for('register') }}">Register</a>

위 라인을 추가하여 아래와 같이 변경합니다.

<!-- vim app001/templates/index.html -->

<!DOCTYPE html>
<html>
        <head>
                <meta charset="utf-8">
                <title>Login</title>
                <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
                <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css">
        </head>
        <body>
                <div class="login">
                        <h1>Login</h1>
                        <div class="links">
                                <a href="{{ url_for('login') }}" class="active">Login</a>
                                <a href="{{ url_for('register') }}">Register</a>
                        </div>
                        <form action="{{ url_for('login') }}" method="post">
                                <label for="username">
                                        <i class="fas fa-user"></i>
                                </label>
                                <input type="text" name="username" placeholder="Username" id="username" required>
                                <label for="password">
                                        <i class="fas fa-lock"></i>
                                </label>
                                <input type="password" name="password" placeholder="Password" id="password" required>
                                <div class="msg">{{ msg }}</div>
                                <input type="submit" value="Login">
                        </form>
                </div>
        </body>
</html>

 

 

 

2. register route 추가

# vim app001/routes.py

# ...

# http://host:5005/register - this will be register page
@app.route('/register', methods=['GET', 'POST'])
def register():
    msg = 'Creating User Page'
    # If already loggedin, redirect to home
    if 'loggedin' in session:
        return redirect(url_for('home'))
    if request.method == 'POST' and 'username' in request.form and 'password' in request.form and 'email' in request.form:
        username = request.form['username']
        password = request.form['password']
        email = request.form['email']
        username_already_exist = User.check_username_exist(username)
        email_already_exist = User.check_email_exist(email)
        if username_already_exist:
            msg = 'That username is already exist'
        elif email_already_exist:
            msg = 'That email is already exist'
        else:
            User.useradd(username, password, email)
            msg = 'Create User Success!'
            return redirect(url_for('login'))
    return render_template('register.html', msg=msg)
    
# ...

 

 

 

3. register web page 추가

<!-- vim app001/templates/register.html -->

<!DOCTYPE html>
<html>
        <head>
                <meta charset="utf-8">
                <title>Register</title>
                <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
                <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css">
        </head>
        <body>
                <div class="login">
                        <h1>Register</h1>
                        <div class="links">
                                <a href="{{ url_for('login') }}">Login</a>
                                <a href="{{ url_for('register') }}" class="active">Register</a>
                        </div>
                        <form action="{{ url_for('register') }}" method="post">

                                <label for="username">
                                        <i class="fas fa-user"></i>
                                </label>
                                <input type="text" name="username" placeholder="Username" id="username" required>

                                <label for="password">
                                        <i class="fas fa-lock"></i>
                                </label>
                                <input type="password" name="password" placeholder="Password" id="password" required>

                                <label for="email">
                                        <i class="fas fa-user"></i>
                                </label>
                                <input type="email" name="email" placeholder="Email" id="email" required>

                                <div class="msg">{{ msg }}</div>
                                <input type="submit" value="Register my user">
                        </form>
                </div>
        </body>
</html>

 

 

 

+ Recent posts