diff --git a/.gitignore b/.gitignore index af79c14..9e9db91 100644 --- a/.gitignore +++ b/.gitignore @@ -140,3 +140,4 @@ cython_debug/ .idea +data-dev.sqlite diff --git a/app/auth/views.py b/app/auth/views.py index 943955a..83e12a7 100644 --- a/app/auth/views.py +++ b/app/auth/views.py @@ -25,6 +25,29 @@ def before_request(): return redirect(url_for('auth.unconfirmed')) +@auth.route('/logintest', methods=['GET', 'POST']) +def logintest(): + if request.method == 'GET': + return render_template('auth/login-and-register.html') + if request.method == 'POST': + student_id = request.form["user"] + password = request.form["pwd"] + user = User.query.filter_by(student_id=student_id).first() + if user is None: + flash("Your StudentID/OrganizationID has not been registered") + return render_template('auth/login.html') + elif user.verify_password(password) is False: + flash("StudentID/OrganizationID or password error") + return render_template('auth/login.html') + if user is not None and user.verify_password(password): + login_user(user, True) + next = request.args.get('next') + if next is None or not next.startswith('/'): + next = url_for('main.index') + return redirect(next) + return render_template('auth/login.html') + + # 登录 @auth.route('/login', methods=['GET', 'POST']) def login(): diff --git a/app/main/views.py b/app/main/views.py index d92136c..37d76db 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -510,12 +510,13 @@ def like(post_id): @main.route('/AJAXlike/',methods=['POST'], strict_slashes=False) -@login_required +# @login_required @csrf.exempt @permission_required(Permission.FOLLOW) def AJAXlike(post_id): + if(current_user is None): + return redirect(url_for("/")) post = Post.query.filter_by(id=post_id).first() - if post is not None: if(current_user.is_liking(post)): current_user.dislike(post) diff --git a/app/static/js/login-and-register.js b/app/static/js/login-and-register.js new file mode 100644 index 0000000..cb3923f --- /dev/null +++ b/app/static/js/login-and-register.js @@ -0,0 +1,23 @@ + +var signUpButton = document.getElementById('signUp') +var signInButton = document.getElementById('signIn') +var container = document.getElementById('mainbox') + +signUpButton.addEventListener('click', function () { + container.classList.add('right-panel-active') +}) + +signInButton.addEventListener('click', function () { + container.classList.remove('right-panel-active') +}); + +function check_email(str){ +  var pattern = new RegExp("@"); + var email = document.getElementById("email"); +  if (pattern.test(str.value)){ +  } + else{ + alert("Please enter correct email address!") + email.focus(); + } +} \ No newline at end of file diff --git a/app/static/login-and-register.css b/app/static/login-and-register.css new file mode 100644 index 0000000..dcc4b7a --- /dev/null +++ b/app/static/login-and-register.css @@ -0,0 +1,236 @@ + +* { + box-sizing: border-box; +} + +body { + font-family: 'Monaco', sans-serif; + background: #f6f5f7; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + height: 100vh; + /*margin: -20px 0 50px;*/ +} + +h1 { + font-weight: bold; + margin-bottom: 20px; +} + +p { + font-size: 14px; + line-height: 20px; + letter-spacing: .5px; + /*margin: 20px 0 30px;*/ +} + +span { + font-size: 12px; +} + +a { + color: #333; + font-size: 14px; + text-decoration: none; +} + +.mainbox { + background: #fff; + border-radius: 10px; + box-shadow: 0 14px 28px rgba(0, 0, 0, .25), 0 10px 10px rgba(0, 0, 0, .22); + position: relative; + overflow: hidden; + width: 768px; + max-width: 100%; + min-height: 480px; + margin: 0 auto; + top: 50%; + transform: translate(0, -50%); +} + +.form-container form { + background: #fff; + display: flex; + flex-direction: column; + padding: 0 50px; + height: 100%; + justify-content: center; + align-items: center; + text-align: center; +} + +.social-container { + margin: 20px 0; +} + +.social-container a { + border: 1px solid #ddd; + border-radius: 50%; + display: inline-flex; + justify-content: center; + align-items: center; + margin: 0 5px; + height: 40px; + width: 40px; +} + +.social-container a:hover { + background-color: #eee; +} + +.form-container input { + background: #eee; + border-radius: 10px; + border: none; + /*padding: 12px 15px;*/ + /*margin: 8px 0;*/ + width: 100%; + outline: none; +} + +#login_submit,#register_submit{ + border-radius: 20px; + border: 1px solid #e7a00e; + background: #e7a00e; + color: #fff; + font-size: 12px; + font-weight: bold; + padding: 12px 45px; + letter-spacing: 1px; + text-transform: uppercase; + transition: transform 80ms ease-in; + cursor: pointer; + width: fit-content; +} + +button { + border-radius: 20px; + border: 1px solid #e7a00e; + background: #e7a00e; + color: #fff; + font-size: 12px; + font-weight: bold; + padding: 12px 45px; + letter-spacing: 1px; + text-transform: uppercase; + transition: transform 80ms ease-in; + cursor: pointer; +} + +button:active { + transform: scale(.95); +} + +button:focus { + outline: none; +} + +button.ghost { + background: transparent; + border-color: #fff; +} + +.form-container { + position: absolute; + top: 0; + height: 100%; + transition: all .6s ease-in-out; +} + +.sign-in-container { + left: 0; + width: 50%; + z-index: 2; +} + +.sign-up-container { + left: 0; + width: 50%; + z-index: 1; + opacity: 0; +} + +.overlay-container { + position: absolute; + top: 0; + left: 50%; + width: 50%; + height: 100%; + overflow: hidden; + transition: transform .6s ease-in-out; + z-index: 100; +} + +.overlay { + background: #9f6f0e; + background: linear-gradient(to right, #c58a0f,#e7a00e) no-repeat 0 0 / cover; + color: #fff; + position: relative; + left: -100%; + height: 100%; + width: 200%; + transform: translateY(0); + transition: transform .6s ease-in-out; +} + +.overlay-panel { + position: absolute; + top: 0; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + padding: 0 40px; + height: 100%; + width: 50%; + text-align: center; + transform: translateY(0); + transition: transform .6s ease-in-out; +} + +.overlay-right { + right: 0; + transform: translateY(0); +} + +.overlay-left { + transform: translateY(-20%); +} + +/* Move signin to right */ +.mainbox.right-panel-active .sign-in-container { + transform: translateY(100%); +} + +/* Move overlay to left */ +.mainbox.right-panel-active .overlay-container { + transform: translateX(-100%); +} + +/* Bring signup over signin */ +.mainbox.right-panel-active .sign-up-container { + transform: translateX(100%); + opacity: 1; + z-index: 5; +} + +/* Move overlay back to right */ +.mainbox.right-panel-active .overlay { + transform: translateX(50%); +} + +/* Bring back the text to center */ +.mainbox.right-panel-active .overlay-left { + transform: translateY(0); +} + +/* Same effect for right */ +.mainbox.right-panel-active .overlay-right { + transform: translateY(20%); +} + +form>div{ + width: 100%; +} diff --git a/app/static/signin.css b/app/static/signin.css index b84702d..d2163e9 100644 --- a/app/static/signin.css +++ b/app/static/signin.css @@ -11,7 +11,7 @@ body{ } .form-signin .form-signin-heading, .form-signin .checkbox { - margin-bottom: 10px; + } .form-signin .checkbox { font-weight: normal; @@ -24,7 +24,7 @@ body{ box-sizing: border-box; padding: 10px; font-size: 16px; - margin: 12px 0; + margin: 6px 0; } .form-signin .form-control:focus { z-index: 2; @@ -36,3 +36,8 @@ body{ .navbar-toggle { background-color: #e7a00e; } + +h1{ + margin-bottom: 36px; +} + diff --git a/app/templates/Posts/_posts.html b/app/templates/Posts/_posts.html index 2dad0a2..4fec995 100644 --- a/app/templates/Posts/_posts.html +++ b/app/templates/Posts/_posts.html @@ -94,7 +94,7 @@ {#data: JSON.stringify(sendData),#} success: function(result) { - console.log(result); + console.log('success\n'+result); if(result.like){ span1.setAttribute('class', 'glyphicon glyphicon-heart'); }else{ @@ -105,6 +105,9 @@ }, error:function(msg){ console.log(msg); + if(msg.status===403){ + window.location.href='{{ url_for('auth.login') }}' + } } }) }"> diff --git a/app/templates/auth/login-and-register.html b/app/templates/auth/login-and-register.html new file mode 100644 index 0000000..d029d09 --- /dev/null +++ b/app/templates/auth/login-and-register.html @@ -0,0 +1,185 @@ +{% extends "base.html" %} + + +{% block title %}Login{% endblock %} + + +{% block head %} + {{ super() }} + + + + + + + + + + + + +{% endblock %} + + + + +{% block body %} +
+
+ + +
+
+
+

Existing account?

+

Go to Sign In

+ +
+
+

No Account?

+

Join us Now

+ +
+
+
+
+ + + +
+ + +{% endblock %} diff --git a/migrations/README b/migrations/README old mode 100755 new mode 100644 diff --git a/migrations/env.py b/migrations/env.py old mode 100755 new mode 100644 diff --git a/migrations/script.py.mako b/migrations/script.py.mako old mode 100755 new mode 100644