create registration endpoint
This commit is contained in:
commit
8de129c2da
11 changed files with 92 additions and 14 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import api
|
||||||
import models
|
import models
|
||||||
import utils
|
import user
|
||||||
import user
|
import utils
|
|
@ -1,5 +1,5 @@
|
||||||
from flask.ext.sqlalchemy import SQLAlchemy
|
from flask.ext.sqlalchemy import SQLAlchemy
|
||||||
import api.utils
|
import utils
|
||||||
|
|
||||||
db = SQLAlchemy()
|
db = SQLAlchemy()
|
||||||
|
|
||||||
|
@ -17,4 +17,4 @@ class Users(db.Model):
|
||||||
self.username = username
|
self.username = username
|
||||||
self.username_lower = username.lower()
|
self.username_lower = username.lower()
|
||||||
self.email = email.lower()
|
self.email = email.lower()
|
||||||
self.password = api.utils.hash_password(password)
|
self.password = utils.hash_password(password)
|
|
@ -0,0 +1,9 @@
|
||||||
|
from flask import Blueprint
|
||||||
|
from utils import api_wrapper
|
||||||
|
|
||||||
|
blueprint = Blueprint("user", __name__)
|
||||||
|
|
||||||
|
@blueprint.route("/register", methods=["POST"])
|
||||||
|
@api_wrapper
|
||||||
|
def user_register():
|
||||||
|
return { "success": 0, "message": "Registration is not open yet." }
|
|
@ -1,21 +1,43 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
import json
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
from functools import wraps
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
|
||||||
|
class WebException(Exception): pass
|
||||||
|
|
||||||
def hash_password(s):
|
def hash_password(s):
|
||||||
return generate_password_hash(s)
|
return generate_password_hash(s)
|
||||||
|
|
||||||
def check_password(hashed_password, try_password):
|
def check_password(hashed_password, try_password):
|
||||||
return check_password_hash(hashed_password, try_password)
|
return check_password_hash(hashed_password, try_password)
|
||||||
|
|
||||||
def generate_string(length):
|
def generate_string(length):
|
||||||
return "".join([random.choice(string.letters + string.digits) for x in range(length)])
|
return "".join([random.choice(string.letters + string.digits) for x in range(length)])
|
||||||
|
|
||||||
def unix_time_millis(dt):
|
def unix_time_millis(dt):
|
||||||
epoch = datetime.datetime.utcfromtimestamp(0)
|
epoch = datetime.datetime.utcfromtimestamp(0)
|
||||||
return (dt - epoch).total_seconds() * 1000.0
|
return (dt - epoch).total_seconds() * 1000.0
|
||||||
|
|
||||||
def get_time_since_epoch():
|
def get_time_since_epoch():
|
||||||
return unix_time_millis(datetime.datetime.now())
|
return unix_time_millis(datetime.datetime.now())
|
||||||
|
|
||||||
|
def api_wrapper(f):
|
||||||
|
@wraps(f)
|
||||||
|
def wrapper(*args, **kwds):
|
||||||
|
web_result = {}
|
||||||
|
response = 200
|
||||||
|
try:
|
||||||
|
web_result = f(*args, **kwds)
|
||||||
|
except WebException as error:
|
||||||
|
response = 200
|
||||||
|
web_result = { "success": 0, "message": str(error) }
|
||||||
|
except Exception as error:
|
||||||
|
response = 200
|
||||||
|
traceback.print_exc()
|
||||||
|
web_result = { "success": 0, "message": "Something went wrong! Please notify us about this immediately.", error: traceback.format_exc() }
|
||||||
|
return json.dumps(web_result), response, { "Content-Type": "application/json; charset=utf-8" }
|
||||||
|
return wrapper
|
|
@ -3,12 +3,16 @@ from flask import Flask
|
||||||
|
|
||||||
import config
|
import config
|
||||||
import json
|
import json
|
||||||
|
import api
|
||||||
|
|
||||||
|
from api.api import api as api_blueprint
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = config.SECRET
|
app.secret_key = config.SECRET
|
||||||
|
app.register_blueprint(api_blueprint)
|
||||||
|
|
||||||
@app.route("/api")
|
@app.route("/api")
|
||||||
def api():
|
def api_main():
|
||||||
return json.dumps({ "success": 1, "message": "The API is online." })
|
return json.dumps({ "success": 1, "message": "The API is online." })
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -26,6 +30,7 @@ if __name__ == "__main__":
|
||||||
from api.models import db
|
from api.models import db
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
db.create_all()
|
db.create_all()
|
||||||
print db
|
|
||||||
|
|
||||||
app.run(host="0.0.0.0", port=8000)
|
app.register_blueprint(api.user.blueprint, url_prefix="/api/user")
|
||||||
|
|
||||||
|
app.run(host="0.0.0.0", port=8000)
|
||||||
|
|
9
web/about.html
Normal file
9
web/about.html
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>About</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>EasyCTF is Fun!</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1,4 +1,7 @@
|
||||||
var app = angular.module('myApp', []);
|
var app = angular.module('myApp', []);
|
||||||
app.controller('myCtrl', function($scope) {
|
app.controller('myCtrl', function($scope) {
|
||||||
$scope.test = "Successful!";
|
$scope.test = "Successful!";
|
||||||
|
if($scope.test == "Successful!") {
|
||||||
|
document.getElementById("result").style.color="#00FF00";
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
<html ng-app="myApp" ng-controller="myCtrl">
|
<html ng-app="myApp" ng-controller="myCtrl">
|
||||||
<head>
|
<head>
|
||||||
<title>EasyCTF 2016</title>
|
<title>EasyCTF 2016</title>
|
||||||
|
<link type="text/css" rel="stylesheet" href="style.css">
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js" integrity="sha384-r1y8TJcloKTvouxnYsi4PJAx+nHNr90ibsEn3zznzDzWBN9X3o3kbHLSgcIPtzAp" crossorigin="anonymous"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js" integrity="sha384-r1y8TJcloKTvouxnYsi4PJAx+nHNr90ibsEn3zznzDzWBN9X3o3kbHLSgcIPtzAp" crossorigin="anonymous"></script>
|
||||||
<script src="ascript.js"></script>
|
<script src="ascript.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Angular.js Status: <span style="color:lime;">{{test}}</span></h1>
|
<marquee id="status">Angular.js Status: <span ng-bind="test" style="color:red" id="result">Failed!</span></marquee>
|
||||||
|
<ul>
|
||||||
|
<li><a href="./">Home</a></li>
|
||||||
|
<li><a href="./about.html">About</a></li>
|
||||||
|
<li><a href="./login.html">Login</a></li>
|
||||||
|
<li><a href="./register.html">Register</a></li>
|
||||||
|
</ul>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
9
web/login.html
Normal file
9
web/login.html
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Login</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Please Login to EasyCTF</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
9
web/register.html
Normal file
9
web/register.html
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Register</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Please Register for EasyCTF</h1>
|
||||||
|
</body>
|
||||||
|
<html>
|
4
web/style.css
Normal file
4
web/style.css
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
marquee {
|
||||||
|
background-color: black;
|
||||||
|
color:white;
|
||||||
|
}
|
Loading…
Reference in a new issue