프로젝트

일반

사용자정보

개정판 5aa151cb

ID5aa151cbd3e97e4e03470bc3a491fd81ee50ca9f
상위 78a9d434
하위 ec3c920c, e405c3e0

백흠경이(가) 4년 이상 전에 추가함

issue #1366: modified generate license key routine

Change-Id: I3f88eeb6c6d8b836a5286a03da051f7ad9cdd777

차이점 보기:

DTI_PID/WebServer/app.py
1
# run.py
1
# app.py
2 2

  
3 3
# Add your settings here... this is a temporary location, as the settings for a Flask app
4 4
# should be stored separate from your main program.
......
7 7
from app import app
8 8

  
9 9
if __name__ == "__main__":
10
    app.run()
10
    app.run(debug=False)
DTI_PID/WebServer/app/__init__.py
10 10
################
11 11
 
12 12
app = Flask(__name__)
13
app.config['SECRET_KEY'] = 'id2 web service'
13 14

  
14 15
@app.route('/')
15 16
def index():
DTI_PID/WebServer/app/license/index.py
2 2
# pwd : /project_name/app/license/index.py
3 3

  
4 4
from flask import Blueprint, request, render_template, flash, redirect, url_for
5
from flask_wtf import FlaskForm
6
from wtforms import *
7
from wtforms.validators import *
5 8
from flask import current_app as app
6 9

  
7 10
license_service = Blueprint('license', __name__, url_prefix='/license')
8 11

  
9 12

  
10
@license_service.route('/', methods=['GET'])
11
def index():
12
    return render_template("/license/index.html")
13

  
14

  
15
@license_service.route('/gen_key', methods=['POST'])
16
def gen_key():
17
    import base64
13
class LicenseForm(FlaskForm):
14
    csrf_token = 'id2 web service'
15
    authorization = PasswordField('Authorization :')
16
    computer_name = StringField('Computer Name :')
17
    submit = SubmitField('Submit')
18 18

  
19
    if request.method == 'POST':
20
        r = request
19
    @staticmethod
20
    def generate_license_key(pw: str, clear: str) -> str:
21
        import base64
21 22

  
22 23
        key = 'Image Drawing to Intelligent Drawing'
23 24

  
24
        pw = r.form['Authorization']
25
        clear = r.form['Computer_Name']
26

  
27 25
        if pw != 'admin':
28 26
            return 'Invalid Authorization'
29 27

  
......
35 33

  
36 34
        new_key = base64.urlsafe_b64encode(bytes(enc))
37 35

  
38
        return 'License Key for ' + clear + ' : ' + new_key.decode('utf-8')
36
        return new_key.decode('utf-8')
37

  
38

  
39
@license_service.route('/', methods=['GET', 'POST'])
40
def index():
41
    authorization = None
42
    computer_name = None
43
    code = None
44

  
45
    form = LicenseForm()
46
    if form.validate_on_submit():
47
        authorization = form.authorization.data
48
        computer_name = form.computer_name.data
49
        code = LicenseForm.generate_license_key(authorization, computer_name)
50
        form.authorization.data = ''
51
        form.computer_name.data = ''
52

  
53
    return render_template("/license/index.html", form=form, authorization=authorization, computer_name=computer_name,
54
                           code=code)
55

  
DTI_PID/WebServer/app/templates/license/index.html
1
<html>
2
   <body>
3
      <form action = "/license/gen_key" method = "POST">
4
         <p>Authorization : <input type = "password" name ="Authorization" /></p>
5
         <p>Computer Name : <input type = "text" name = "Computer_Name" /></p>
6
         <p><input type = "submit" value = "submit" /></p>
7
      </form>
8
   </body>
9
</html>
1
{% block content %}
2
<div class="container">
3
    <div class="page-header">
4
        <h1>Your License Code is : {% if code %} {{ code }} {% else %} None {% endif %}</h1>
5

  
6
        <form method="POST">
7
            {{ form.csrf_token }}
8
            <table border="0">
9
                <tr><td>{{ form.authorization.label }}</td><td>{{ form.authorization() }}</td></tr>
10
                <tr><td>{{ form.computer_name.label }}</td><td>{{ form.computer_name() }}</td></tr>
11
                <tr><td>{{ form.submit() }}</td></tr>
12
            </table>
13
        </form>
14
    </div>
15
</div>
16
{% endblock %}

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)