update templates
This commit is contained in:
parent
9129acd1a6
commit
77671bb560
9 changed files with 103 additions and 41 deletions
21
README.md
21
README.md
|
@ -1 +1,20 @@
|
|||
## wtstts/wots-server
|
||||
# World of Tanks Statistics Server
|
||||
|
||||
## Requirements
|
||||
|
||||
- Ubuntu/Debian Linux
|
||||
- Postgresql
|
||||
- Python 2.7
|
||||
- Wargaming Developers Account
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### Run
|
||||
|
||||
```
|
||||
python app.py
|
||||
```
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""empty message
|
||||
"""INIT
|
||||
|
||||
Revision ID: f5e44761054e
|
||||
Revises:
|
||||
|
@ -21,10 +21,11 @@ def upgrade():
|
|||
'user',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('status', sa.Integer(), nullable=False, default=0),
|
||||
sa.Column('name', sa.String(256), nullable=False, unique=True),
|
||||
sa.Column('email', sa.String(length=256), nullable=False, unique=True),
|
||||
sa.Column('password', sa.String(32), nullable=False),
|
||||
sa.Column('openid', sa.String(256), nullable=True, unique=True),
|
||||
sa.Column('name', sa.String(256), nullable=False, unique=True),
|
||||
sa.Column('token', sa.String(length=256), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
pass
|
||||
|
|
|
@ -17,8 +17,10 @@ depends_on = None
|
|||
|
||||
|
||||
def upgrade():
|
||||
# op.add_column('user', sa.Column('token', sa.String(256), nullable=True, ))
|
||||
pass
|
||||
|
||||
|
||||
def downgrade():
|
||||
# op.drop_column('user', 'token')
|
||||
pass
|
||||
|
|
|
@ -4,6 +4,7 @@ from wotstats.database import db, migrate
|
|||
from wotstats.openid import oid
|
||||
from wotstats.views.home import pages_home
|
||||
from wotstats.views.account import pages_account
|
||||
from wotstats.views.wallet import pages_wallet
|
||||
|
||||
def init_app():
|
||||
app = Flask(__name__)
|
||||
|
@ -11,10 +12,11 @@ def init_app():
|
|||
app.config['SECRET_KEY'] = 'super-secret'
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres://wot:wot@192.168.1.47/wot'
|
||||
app.config['OPENID_FS_STORE_PATH'] = 'tmp'
|
||||
#
|
||||
# TODO: rename to WG_APPLICATION_ID
|
||||
app.config['WG_ID'] = '502910c1c785c3c7ca2e83c9e89bde02'
|
||||
# app.config['WG_OPENID_URL'] = 'https://eu.wargaming.net/id/openid/'
|
||||
app.config['WG_OPENID_URL'] = 'https://wargaming.net/id/openid/'
|
||||
app.config['WG_TOKEN_URL'] = 'https://api.worldoftanks.ru/wot/auth/login/'
|
||||
|
||||
# , safe_roots=[]
|
||||
oid.init_app(app)
|
||||
|
@ -24,6 +26,7 @@ def init_app():
|
|||
|
||||
app.register_blueprint(pages_home)
|
||||
app.register_blueprint(pages_account)
|
||||
app.register_blueprint(pages_wallet)
|
||||
|
||||
@app.before_request
|
||||
def lookup_current_user():
|
||||
|
|
|
@ -9,6 +9,7 @@ class User(db.Model):
|
|||
password = db.Column(db.String(32), nullable=False)
|
||||
name = db.Column(db.String(256), unique=True, nullable=False)
|
||||
openid = db.Column(db.String(256), unique=True, nullable=True)
|
||||
token = db.Column(db.String(256), nullable=True)
|
||||
|
||||
def __init__(self, email):
|
||||
self.email = email
|
||||
|
|
|
@ -1,24 +1,36 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>{% block title %}{% endblock %}</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<!-- load MUI -->
|
||||
<link href="//cdn.muicss.com/mui-0.9.22/css/mui.min.css" rel="stylesheet" type="text/css" />
|
||||
<script src="//cdn.muicss.com/mui-0.9.22/js/mui.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="mui-container">
|
||||
<div class="mui-panel">
|
||||
<h1>wotstats</h1>
|
||||
{% if session['openid'] %}
|
||||
<ul>
|
||||
<div>
|
||||
{% if 'openid' in session %}
|
||||
<li>{{ session['openid'] }}</li>
|
||||
<!-- {{ session['openid'] }} -->
|
||||
{% else %}
|
||||
<li>{{ session['email'] }}</li>
|
||||
<!-- {{ session['email'] }} -->
|
||||
{% endif %}
|
||||
<li><a href="{{ url_for('pages_account.index') }}">my statistics</a></li>
|
||||
<li><a href="{{ url_for('pages_home.logout') }}">logout</a></li>
|
||||
</ul>
|
||||
<a href="{{ url_for('pages_account.index') }}" class="mui-btn mui-btn--raised">my statistics</a>
|
||||
<a href="{{ url_for('pages_wallet.index') }}" class="mui-btn mui-btn--raised">wallet</a>
|
||||
<a href="{{ url_for('pages_home.logout') }}" class="mui-btn mui-btn--primary mui-btn--raised">logout</a>
|
||||
</div>
|
||||
{% else %}
|
||||
<ul>
|
||||
<li><a href="{{ url_for('pages_home.login') }}">login</a></li>
|
||||
</ul>
|
||||
<div>
|
||||
<a href="{{ url_for('pages_home.login') }}" class="mui-btn mui-btn--primary mui-btn--raised">Sign In</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% block content %}{% endblock %}
|
||||
<!-- <button class="mui-btn mui-btn--primary mui-btn--raised">My Button</button> -->
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
{% extends 'layouts/main.html' %}
|
||||
|
||||
{% block content %}
|
||||
{# {account_statistics} #}
|
||||
|
||||
|
||||
|
||||
<h2>My Statistics</h2>
|
||||
<ul>
|
||||
{% for z in account_statistics %}
|
||||
<li>{{ z }}
|
||||
|
|
|
@ -5,9 +5,8 @@
|
|||
<form action="" method="post">
|
||||
{% if error %}<p class=error><strong>Error:</strong> {{ error }}</p>{% endif %}
|
||||
<p>
|
||||
Wargaming OpenID:
|
||||
<input type="hidden" name="openid" value="{{ config['WG_OPENID_URL'] }}">
|
||||
<input type="submit" value="Sign in">
|
||||
<input type="submit" value="Wargaming OpenID" class="mui-btn mui-btn--primary mui-btn--raised">
|
||||
<input type="hidden" name="next" value="{{ next }}">
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import re
|
||||
import requests
|
||||
from flask import (
|
||||
g, Blueprint, render_template, abort, current_app, redirect,
|
||||
redirect, request, url_for, session, flash
|
||||
|
@ -17,31 +18,24 @@ pages_home = Blueprint('pages_home', __name__, template_folder='templates')
|
|||
# except TemplateNotFound:
|
||||
# abort(404)
|
||||
|
||||
def parse_wargaming_openid_url(url):
|
||||
"""
|
||||
>>> parse_wargaming_openid_url('https://ru.wargaming.net/id/69552613-CrazyPants1999/')
|
||||
('69552613', 'CrazyPants1999')
|
||||
|
||||
"""
|
||||
pattern = '^https?.*id\/([0-9]+)-(\w+)\/$'
|
||||
return re.findall(pattern, url)[0]
|
||||
|
||||
|
||||
@pages_home.route('/', defaults={'page': 'index'})
|
||||
@pages_home.route('/<page>')
|
||||
def index(page):
|
||||
# z = session['openid']
|
||||
print session
|
||||
return render_template('pages/index.html')
|
||||
|
||||
|
||||
@pages_home.route('/auth.html')
|
||||
def auth_step1():
|
||||
return render_template('pages/auth_step1.html')
|
||||
# @pages_home.route('/auth.html')
|
||||
# def auth_step1():
|
||||
# return render_template('pages/auth_step1.html')
|
||||
|
||||
|
||||
@pages_home.route('/login', methods=['GET', 'POST'])
|
||||
@oid.loginhandler
|
||||
def login():
|
||||
print request.form
|
||||
print request.args
|
||||
if g.user is not None:
|
||||
return redirect(oid.get_next_url())
|
||||
if request.method == 'POST':
|
||||
|
@ -86,17 +80,51 @@ def create_profile():
|
|||
@pages_home.route('/logout')
|
||||
def logout():
|
||||
session.pop('openid', None)
|
||||
flash(u'You were signed out')
|
||||
session.pop('token', None)
|
||||
# flash(u'You were signed out')
|
||||
return redirect(oid.get_next_url())
|
||||
|
||||
|
||||
@pages_home.route('/token')
|
||||
def token():
|
||||
print request.args
|
||||
print request.form
|
||||
|
||||
if 'openid' not in session:
|
||||
return redirect(url_for('pages_home.index'))
|
||||
# ImmutableMultiDict([('status', u'ok'), ('access_token', u'a4d0a13df7c733102fbf6cd650794c6d047e91aa'), ('nickname', u'CrazyPants1999'), ('account_id', u'69552613'), ('', u'1505047809')])
|
||||
if request.args.get('status') == 'ok' and request.args.get('access_token'):
|
||||
session['token'] = {
|
||||
'access_token': request.args.get('access_token'),
|
||||
'expires_at': request.args.get('expires_at'),
|
||||
}
|
||||
return redirect(oid.get_next_url())
|
||||
|
||||
redirect_url = 'http://truesoft.org:5000/token'
|
||||
|
||||
response = requests.get('{}?application_id={}&nofollow=1&redirect_uri={}'.format(
|
||||
current_app.config['WG_TOKEN_URL'],
|
||||
current_app.config['WG_ID'], redirect_url)).json()
|
||||
|
||||
if response.get('status') == 'ok':
|
||||
return redirect(response.get('data', {}).get('location'))
|
||||
return redirect(oid.get_next_url())
|
||||
|
||||
|
||||
@oid.after_login
|
||||
def create_or_login(resp):
|
||||
session['openid'] = resp.identity_url
|
||||
session['token'] = None
|
||||
|
||||
user = User.query.filter_by(openid=resp.identity_url).first()
|
||||
|
||||
if user is not None:
|
||||
flash(u'Successfully signed in')
|
||||
# flash(u'Successfully signed in')
|
||||
g.user = user
|
||||
if not session['token']:
|
||||
return redirect(url_for('pages_home.token'))
|
||||
return redirect(oid.get_next_url())
|
||||
|
||||
return redirect(url_for(
|
||||
'pages_home.create_profile',
|
||||
next=oid.get_next_url(),
|
||||
|
|
Reference in a new issue