create registration endpoint

This commit is contained in:
Michael Zhang 2015-12-23 17:23:18 -06:00
commit 8de129c2da
11 changed files with 92 additions and 14 deletions

View file

@ -1,3 +1,4 @@
import api
import models
import utils
import user
import utils

View file

@ -1,5 +1,5 @@
from flask.ext.sqlalchemy import SQLAlchemy
import api.utils
import utils
db = SQLAlchemy()
@ -17,4 +17,4 @@ class Users(db.Model):
self.username = username
self.username_lower = username.lower()
self.email = email.lower()
self.password = api.utils.hash_password(password)
self.password = utils.hash_password(password)

View file

@ -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." }

View file

@ -1,9 +1,14 @@
import datetime
import json
import random
import string
import traceback
from functools import wraps
from werkzeug.security import generate_password_hash, check_password_hash
class WebException(Exception): pass
def hash_password(s):
return generate_password_hash(s)
@ -19,3 +24,20 @@ def unix_time_millis(dt):
def get_time_since_epoch():
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

View file

@ -3,12 +3,16 @@ from flask import Flask
import config
import json
import api
from api.api import api as api_blueprint
app = Flask(__name__)
app.secret_key = config.SECRET
app.register_blueprint(api_blueprint)
@app.route("/api")
def api():
def api_main():
return json.dumps({ "success": 1, "message": "The API is online." })
if __name__ == "__main__":
@ -26,6 +30,7 @@ if __name__ == "__main__":
from api.models import db
db.init_app(app)
db.create_all()
print db
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
View file

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>About</title>
</head>
<body>
<h1>EasyCTF is Fun!</h1>
</body>
</html>

View file

@ -1,4 +1,7 @@
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.test = "Successful!";
if($scope.test == "Successful!") {
document.getElementById("result").style.color="#00FF00";
}
});

View file

@ -1,10 +1,17 @@
<html ng-app="myApp" ng-controller="myCtrl">
<head>
<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="ascript.js"></script>
</head>
<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>
</html>

9
web/login.html Normal file
View 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
View 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
View file

@ -0,0 +1,4 @@
marquee {
background-color: black;
color:white;
}