Browse Source

Merge remote-tracking branch 'origin/efe' into yigit

old
Yiğit Çolakoğlu 6 years ago
parent
commit
8002176c87
19 changed files with 182 additions and 154 deletions
  1. +2
    -1
      MyCity/app/src/main/AndroidManifest.xml
  2. +4
    -16
      server_side/api/app.py
  3. BIN
      server_side/api/login/__pycache__/__init__.cpython-37.pyc
  4. BIN
      server_side/api/login/__pycache__/login.cpython-37.pyc
  5. +0
    -28
      server_side/api/login/login.py
  6. +0
    -3
      server_side/api/login/userdata.json
  7. +0
    -0
      server_side/api/modules/__init__.py
  8. +3
    -11
      server_side/api/modules/databases/ratings.json
  9. +2
    -1
      server_side/api/modules/databases/users.json
  10. +5
    -1
      server_side/api/modules/databases/votings.json
  11. +33
    -18
      server_side/api/modules/rating_system.py
  12. +84
    -0
      server_side/api/modules/user_info.py
  13. +16
    -0
      server_side/api/modules/utils.py
  14. +33
    -11
      server_side/api/modules/voting_system.py
  15. +0
    -0
      server_side/api/rating_system/__init__.py
  16. +0
    -0
      server_side/api/user_info/__init__.py
  17. +0
    -64
      server_side/api/user_info/user_info.py
  18. +0
    -0
      server_side/api/voting_system/__init__.py
  19. BIN
      server_side/api/voting_system/__pycache__/voting_system.cpython-37.pyc

+ 2
- 1
MyCity/app/src/main/AndroidManifest.xml View File

@ -12,7 +12,8 @@
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
android:theme="@style/AppTheme.NoActionBar"
android:screenOrientation="portrait">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>


+ 4
- 16
server_side/api/app.py View File

@ -1,17 +1,11 @@
from flask import Flask, send_from_directory from flask import Flask, send_from_directory
from flask_restful import Resource, Api from flask_restful import Resource, Api
from voting_system import voting_system
from rating_system import rating_system
from login import login
from user_info import user_info
from login import login
from modules import voting_system, rating_system, user_info
app = Flask(__name__) app = Flask(__name__)
api = Api(app) api = Api(app)
@app.route('/img/<path:path>') @app.route('/img/<path:path>')
def send_img(path): def send_img(path):
return send_from_directory('images', path) return send_from_directory('images', path)
@ -27,14 +21,8 @@ if __name__ == '__main__':
api.add_resource(rating_system.Rating, '/ratings/<int:rating_id>', '/ratings/<int:rating_id>/') api.add_resource(rating_system.Rating, '/ratings/<int:rating_id>', '/ratings/<int:rating_id>/')
api.add_resource(rating_system.Rate, '/rate', '/rate/') api.add_resource(rating_system.Rate, '/rate', '/rate/')
api.add_resource(login.Login, '/login', '/login/')
app.run(host='0.0.0.0', port=5000, ssl_context=context)
api.add_resource(user_info.Users, '/users', '/users/') api.add_resource(user_info.Users, '/users', '/users/')
api.add_resource(user_info.User, '/users/<int:user_id>', '/users/<int:user_id>/')
app.run(host='0.0.0.0', port=5000)
api.add_resource(login.Login, '/login', '/login/')
api.add_resource(user_info.User, '/users/<path:user_id>', '/users/<path:user_id>/')
api.add_resource(user_info.Login, '/login', '/login/')
app.run(host='0.0.0.0', port=5000, ssl_context=context) app.run(host='0.0.0.0', port=5000, ssl_context=context)

BIN
server_side/api/login/__pycache__/__init__.cpython-37.pyc View File


BIN
server_side/api/login/__pycache__/login.cpython-37.pyc View File


+ 0
- 28
server_side/api/login/login.py View File

@ -1,28 +0,0 @@
import os
import json
import hashlib
from flask import Flask, request
from flask_restful import Resource, Api, abort
app = Flask(__name__)
api = Api(app)
with open(os.path.join(app.root_path, 'userdata.json'), 'r') as f:
data = json.load(f)
class Login( Resource ):
def post(self):
req = request.args
print(req)
if __name__ == '__main__':
api.add_resource(Login, '/login', '/login/')
app.run(host='0.0.0.0', port=5000)

+ 0
- 3
server_side/api/login/userdata.json View File

@ -1,3 +0,0 @@
{
}

server_side/api/login/__init__.py → server_side/api/modules/__init__.py View File


server_side/api/rating_system/ratings.json → server_side/api/modules/databases/ratings.json View File


server_side/api/user_info/users.json → server_side/api/modules/databases/users.json View File


server_side/api/voting_system/votings.json → server_side/api/modules/databases/votings.json View File


server_side/api/rating_system/rating_system.py → server_side/api/modules/rating_system.py View File


+ 84
- 0
server_side/api/modules/user_info.py View File

@ -0,0 +1,84 @@
import os
import json
from . import utils
from flask import Flask, request
from flask_restful import Resource, Api, abort
app = Flask(__name__)
api = Api(app)
db_path = os.path.join(app.root_path, 'databases', 'users.json')
with open(db_path, 'r') as f:
users = json.load(f)
class Users(Resource):
def post(self):
"""
Example POST Data:
username=<username>&
password=<password>&
realname=<realname>& # OPTIONAL
avatar=<avatar_url>& # OPTIONAL
"""
args = request.form
user_id = utils.generate_id()
user = {
'id': user_id,
'username': args['username'],
'realname': args.get('realname'),
'avatar' : args.get('avatar'),
'password': utils.md5(args['password']),
'stats': {
'bus_usage_week': 0,
'bus_usage_month': 0,
'bus_usage_year': 0
},
'points': 0
}
users.append(user)
with open(db_path, 'w') as f:
json.dump(users, f, indent=4)
return user
class User(Resource):
def get(self, user_id):
try:
user = utils.find_by_id(users, user_id)
if not user:
raise Exception('User not found!')
del user['password']
return user
except:
abort(404, error="User {} doesn't exist".format(user_id))
class Login(Resource):
def post(self):
"""
Example POST Data:
username=<username>&
password=<password>
"""
args = request.form
print(args)
username = args['username']
passsword = utils.md5(args['password'])
for user in users:
if user['username'] == username:
if user['password'] == passsword:
return {'message': 'Login successful!', 'id': user['id']}
return {'error': 'Wrong password!'}
return {'error': 'User not found!'}
if __name__ == '__main__':
api.add_resource(Users, '/users', '/users/')
api.add_resource(User, '/users/<path:user_id>', '/users/<path:user_id>/')
api.add_resource(Login, '/login', '/login/')
app.run(host='0.0.0.0', port=5000)

+ 16
- 0
server_side/api/modules/utils.py View File

@ -0,0 +1,16 @@
import string
import random
import hashlib
def md5(s):
return hashlib.md5(s.encode()).hexdigest()
def find_by_id(iterable, _id):
for i in iterable:
if i['id'] == _id:
return i
return None
def generate_id(length=32):
return ''.join(random.choices(string.ascii_lowercase + string.digits, k=length))

server_side/api/voting_system/voting_system.py → server_side/api/modules/voting_system.py View File


+ 0
- 0
server_side/api/rating_system/__init__.py View File


+ 0
- 0
server_side/api/user_info/__init__.py View File


+ 0
- 64
server_side/api/user_info/user_info.py View File

@ -1,64 +0,0 @@
import os
import json
from flask import Flask, request
from flask_restful import Resource, Api, abort
app = Flask(__name__)
api = Api(app)
with open(os.path.join(app.root_path, 'users.json'), 'r') as f:
users = json.load(f)
class Users(Resource):
def get(self):
user = [
{
'id' : v['id'],
'username': v['username']
}
for v in users
]
return user
def post(self):
"""
Example POST Data:
username=<username>&
realname=<realname>& # OPTIONAL
avatar=<avatar_url>& # OPTIONAL
"""
args = request.form
user_id = len(users) + 1
user = {
'id': user_id,
'username': args['username'],
'realname': args.get('realname'),
'avatar' : args.get('avatar'),
'stats': {
'bus_usage_week': 0,
'bus_usage_month': 0,
'bus_usage_year': 0
},
'points': 0
}
users.append(user)
with open(os.path.join(app.root_path, 'users.json'), 'w') as f:
json.dump(users, f, indent=4)
return user
class User(Resource):
def get(self, user_id):
try:
return users[user_id - 1]
except:
abort(404, error="User {} doesn't exist".format(voting_id))
if __name__ == '__main__':
api.add_resource(Users, '/users', '/users/')
api.add_resource(User, '/users/<int:user_id>', '/users/<int:user_id>/')
app.run(host='0.0.0.0', port=5000)

+ 0
- 0
server_side/api/voting_system/__init__.py View File


BIN
server_side/api/voting_system/__pycache__/voting_system.cpython-37.pyc View File


Loading…
Cancel
Save