diff --git a/README.md b/README.md
index acd4c75..9f4eeb2 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,20 @@
-## wtstts/wots-server
\ No newline at end of file
+# 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
+```
diff --git a/alembic/versions/2017_08_26_01_01.py b/alembic/versions/2017_08_26_01_01.py
index 446c16a..f6f3b7e 100644
--- a/alembic/versions/2017_08_26_01_01.py
+++ b/alembic/versions/2017_08_26_01_01.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
diff --git a/alembic/versions/2017_08_27_03_02.py b/alembic/versions/2017_08_27_03_02.py
index 2b6b9c3..97f8a44 100644
--- a/alembic/versions/2017_08_27_03_02.py
+++ b/alembic/versions/2017_08_27_03_02.py
@@ -17,8 +17,10 @@ depends_on = None
def upgrade():
- pass
+ # op.add_column('user', sa.Column('token', sa.String(256), nullable=True, ))
+ pass
def downgrade():
+ # op.drop_column('user', 'token')
pass
diff --git a/wotstats/init.py b/wotstats/init.py
index 2ad29ef..7e9f514 100644
--- a/wotstats/init.py
+++ b/wotstats/init.py
@@ -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():
diff --git a/wotstats/models/user.py b/wotstats/models/user.py
index 3b4f675..9ceb0d6 100644
--- a/wotstats/models/user.py
+++ b/wotstats/models/user.py
@@ -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
diff --git a/wotstats/templates/layouts/main.html b/wotstats/templates/layouts/main.html
index 31086a3..26bf37a 100644
--- a/wotstats/templates/layouts/main.html
+++ b/wotstats/templates/layouts/main.html
@@ -1,24 +1,36 @@
+
{% block title %}{% endblock %}
+
+
+
+
+
- wotstats
- {% if session['openid'] %}
-
- {% if 'openid' in session %}
- - {{ session['openid'] }}
+
+
+
wotstats
+ {% if session['openid'] %}
+
{% else %}
-
- {{ session['email'] }}
+
{% endif %}
-
- my statistics
-
- logout
-
- {% else %}
-
- {% endif %}
- {% block content %}{% endblock %}
+ {% block content %}{% endblock %}
+
+
+
diff --git a/wotstats/templates/pages/account/index.html b/wotstats/templates/pages/account/index.html
index f8b1e60..dcc4682 100644
--- a/wotstats/templates/pages/account/index.html
+++ b/wotstats/templates/pages/account/index.html
@@ -1,10 +1,7 @@
{% extends 'layouts/main.html' %}
{% block content %}
-{# {account_statistics} #}
-
-
-
+ My Statistics
{% for z in account_statistics %}
- {{ z }}
diff --git a/wotstats/templates/pages/login.html b/wotstats/templates/pages/login.html
index 07a7a7c..9c32dbc 100644
--- a/wotstats/templates/pages/login.html
+++ b/wotstats/templates/pages/login.html
@@ -5,9 +5,8 @@
{% endblock %}
diff --git a/wotstats/views/home.py b/wotstats/views/home.py
index 3e37e79..61765e6 100644
--- a/wotstats/views/home.py
+++ b/wotstats/views/home.py
@@ -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('/')
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(),