hytos / DTI_PID / WebServer / app / license / index.py @ e75b5c63
이력 | 보기 | 이력해설 | 다운로드 (1.61 KB)
1 | 78a9d434 | humkyung | # file name : index.py
|
---|---|---|---|
2 | # pwd : /project_name/app/license/index.py
|
||
3 | |||
4 | from flask import Blueprint, request, render_template, flash, redirect, url_for |
||
5 | 5aa151cb | humkyung | from flask_wtf import FlaskForm |
6 | from wtforms import * |
||
7 | from wtforms.validators import * |
||
8 | 78a9d434 | humkyung | from flask import current_app as app |
9 | |||
10 | license_service = Blueprint('license', __name__, url_prefix='/license') |
||
11 | |||
12 | |||
13 | 5aa151cb | humkyung | class LicenseForm(FlaskForm): |
14 | csrf_token = 'id2 web service'
|
||
15 | authorization = PasswordField('Authorization :')
|
||
16 | computer_name = StringField('Computer Name :')
|
||
17 | submit = SubmitField('Submit')
|
||
18 | 78a9d434 | humkyung | |
19 | 5aa151cb | humkyung | @staticmethod
|
20 | def generate_license_key(pw: str, clear: str) -> str: |
||
21 | import base64 |
||
22 | 78a9d434 | humkyung | |
23 | key = 'Image Drawing to Intelligent Drawing'
|
||
24 | |||
25 | if pw != 'admin': |
||
26 | return 'Invalid Authorization' |
||
27 | |||
28 | enc = [] |
||
29 | for i in range(len(clear)): |
||
30 | key_c = key[i % len(key)]
|
||
31 | enc_c = (ord(clear[i]) + ord(key_c)) % 256 |
||
32 | enc.append(enc_c) |
||
33 | |||
34 | new_key = base64.urlsafe_b64encode(bytes(enc))
|
||
35 | |||
36 | 5aa151cb | humkyung | 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) |