-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anand Vemuri
authored and
Anand Vemuri
committed
Apr 23, 2017
0 parents
commit dedb71c
Showing
27 changed files
with
291 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
venv/** | ||
instance/** | ||
migrations/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from flask import Flask | ||
from flask_login import LoginManager | ||
from flask_sqlalchemy import SQLAlchemy | ||
from flask_migrate import Migrate | ||
from flask_wtf.csrf import CSRFProtect | ||
|
||
from config import app_config | ||
|
||
CONFIG_PYFILE = 'config.py' | ||
|
||
login_manager = LoginManager() | ||
db = SQLAlchemy() | ||
LOGIN_MESSAGE = "You Are Unauthorized to View This Page" | ||
LOGIN_VIEW = "auth.login" | ||
csrf = CSRFProtect() | ||
|
||
def create_app(config_name): | ||
app = Flask(__name__,instance_relative_config=True) | ||
app.config.from_object(app_config[config_name]) | ||
app.config.from_pyfile(CONFIG_PYFILE) | ||
|
||
|
||
from .auth import auth as auth_blueprint | ||
app.register_blueprint(auth_blueprint) | ||
|
||
from .home import home as home_blueprint | ||
app.register_blueprint(home_blueprint) | ||
|
||
login_manager.init_app(app) | ||
login_manager.login_message = LOGIN_MESSAGE | ||
login_manager.login_view = LOGIN_VIEW | ||
|
||
db.init_app(app) | ||
csrf.init_app(app) | ||
migrate = Migrate(app,db) | ||
|
||
from app import models | ||
|
||
return app |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from flask import Blueprint | ||
|
||
auth = Blueprint('auth',__name__) | ||
|
||
from . import views |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from flask_wtf import FlaskForm | ||
from wtforms import PasswordField, StringField, SubmitField, ValidationError | ||
from wtforms.validators import DataRequired, EqualTo | ||
|
||
from ..models import User | ||
|
||
|
||
class RegistrationForm(FlaskForm): | ||
username = StringField('username',validators=[DataRequired()]) | ||
password = PasswordField('password', validators=[DataRequired()]) | ||
confirm_password = PasswordField('confirmPassword') | ||
|
||
def validate_username(self,field): | ||
if User.query.filter_by(username=field.data).first(): | ||
raise ValidationError("Username Already in Use") |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from flask import render_template | ||
|
||
|
||
from . import auth | ||
from forms import RegistrationForm | ||
from .. import db | ||
from ..models import User | ||
|
||
@auth.route('/login') | ||
def login(): | ||
return render_template('/auth/login.html') | ||
|
||
@auth.route('/register',methods=['GET','POST']) | ||
def register(): | ||
form = RegistrationForm() | ||
|
||
if form.validate_on_submit(): | ||
|
||
user = User(username=form.username.data, | ||
password=form.password.data) | ||
db.session.add(user) | ||
db.session.commit() | ||
#flash('You have successfully registered! You may now login.') | ||
return redirect(url_for('auth.login')) | ||
print(form.errors) | ||
return render_template('/auth/register.html') |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from flask import Blueprint | ||
|
||
home = Blueprint('home',__name__) | ||
|
||
from . import views | ||
|
||
|
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from flask import render_template | ||
|
||
from . import home | ||
|
||
@home.route('/') | ||
def hello(): | ||
return render_template('home/index.html') |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from flask_login import UserMixin | ||
from werkzeug.security import generate_password_hash, check_password_hash | ||
|
||
from app import db,login_manager | ||
|
||
|
||
class User(UserMixin,db.Model): | ||
__tablename__ = 'users' | ||
|
||
id = db.Column(db.Integer,primary_key=True) | ||
username = db.Column(db.String(60),unique=True,index=True) | ||
password_hash = db.Column(db.String(128)) | ||
|
||
@property | ||
def password(self): | ||
raise AttributeError("Password Attribute not Readable") | ||
|
||
@password.setter | ||
def password(self,password): | ||
self.password_hash = generate_password_hash(password) | ||
|
||
def verify_password(self,password): | ||
return check_password_hash(self.password,password) | ||
|
||
@login_manager.user_loader | ||
def load_user(user_id): | ||
return User.query.get(int(user_id)) |
Binary file not shown.
10 changes: 10 additions & 0 deletions
10
auth-todo-1/app/static/components/registration/RegistrationApp.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var RegistrationApp = React.createClass({ | ||
render : function(){ | ||
return ( | ||
<div> | ||
<RegistrationBanner/> | ||
<RegistrationForm/> | ||
</div> | ||
) | ||
} | ||
}); |
7 changes: 7 additions & 0 deletions
7
auth-todo-1/app/static/components/registration/RegistrationBanner.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var RegistrationBanner = React.createClass({ | ||
render:function(){ | ||
return( | ||
<h3> Register Here!</h3> | ||
) | ||
} | ||
}); |
60 changes: 60 additions & 0 deletions
60
auth-todo-1/app/static/components/registration/RegistrationForm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
var RegistrationForm = React.createClass({ | ||
getInitialState:function(){ | ||
return ({ | ||
username: "", | ||
password:"", | ||
confirmPassword:"" | ||
}); | ||
}, | ||
toggleUsername:function(e){ | ||
this.setState({ | ||
username:e.target.value | ||
}); | ||
}, | ||
togglePassword:function(e){ | ||
this.setState({ | ||
password:e.target.value | ||
}); | ||
}, | ||
toggleConfirmPassword:function(e){ | ||
this.setState({ | ||
confirmPassword:e.target.value | ||
}); | ||
}, | ||
register:function(e){ | ||
console.log(e); | ||
e.preventDefault(); | ||
|
||
if(this.state.password === this.state.confirmPassword){ | ||
|
||
axios.post('/register',{ | ||
username:this.state.username, | ||
password:this.state.password, | ||
confirmPassword:this.state.confirmPassword | ||
|
||
}) | ||
.then(function (response) { | ||
console.log(response); | ||
}) | ||
.catch(function (error) { | ||
console.log(error); | ||
}); | ||
|
||
} | ||
else{ | ||
alert("Passwords are not in alignment"); | ||
} | ||
}, | ||
|
||
render:function(){ | ||
return( | ||
<form onSubmit={this.register}> | ||
<input type="text" value={this.state.username} onChange={this.toggleUsername}/> | ||
<input type="password" value={this.state.password} onChange={this.togglePassword}/> | ||
<input type="password" value={this.state.confirmPassword} onChange={this.toggleConfirmPassword}/> | ||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/> | ||
<input type="submit" value="Register"/> | ||
</form> | ||
) | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<h1> Login Page Under Construction </h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<html lang="en"> | ||
<head> | ||
<script src="https://fb.me/react-0.12.2.js"></script> | ||
<script src="https://fb.me/JSXTransformer-0.12.2.js"></script> | ||
<script src="{{url_for('static',filename='components/registration/RegistrationApp.js')}}" type="text/jsx"></script> | ||
<script src="{{url_for('static',filename='components/registration/RegistrationBanner.js')}}" type="text/jsx"></script> | ||
<script src="{{url_for('static',filename='components/registration/RegistrationForm.js')}}" type="text/jsx"></script> | ||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | ||
</head> | ||
<body> | ||
<div id='registration'></div> | ||
<script type="text/jsx"> | ||
React.renderComponent(<RegistrationApp/>,document.getElementById('registration')); | ||
</script> | ||
<script type="text/javascript"> | ||
var csrf_token = "{{ csrf_token() }}"; | ||
|
||
$.ajaxSetup({ | ||
beforeSend: function(xhr, settings) { | ||
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) { | ||
xhr.setRequestHeader("X-CSRFToken", csrf_token); | ||
} | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!DOCTYPE> | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<h1>Under Construction</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Config(object): | ||
Debug = True | ||
|
||
class ProductionConfig(Config): | ||
Debug = False | ||
|
||
class DevelopmentConfig(Config): | ||
Debug = True | ||
|
||
app_config = { | ||
'development' : DevelopmentConfig, | ||
'production' : ProductionConfig | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
alembic==0.9.1 | ||
appdirs==1.4.3 | ||
click==6.7 | ||
Flask==0.12.1 | ||
Flask-Login==0.4.0 | ||
Flask-Migrate==2.0.3 | ||
Flask-Script==2.0.5 | ||
Flask-SQLAlchemy==2.2 | ||
Flask-WTF==0.14.2 | ||
itsdangerous==0.24 | ||
Jinja2==2.9.6 | ||
Mako==1.0.6 | ||
MarkupSafe==1.0 | ||
MySQL-python==1.2.5 | ||
packaging==16.8 | ||
pyparsing==2.2.0 | ||
python-editor==1.0.3 | ||
six==1.10.0 | ||
SQLAlchemy==1.1.9 | ||
Werkzeug==0.12.1 | ||
WTForms==2.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import os | ||
|
||
from app import create_app | ||
|
||
config_name = os.getenv("FLASK_CONFIG") | ||
app = create_app(config_name) | ||
|
||
if __name__ == '__main__': | ||
app.run() |
Binary file not shown.