def signin(): if g.user.is_authenticated: return redirect(url_for('board')) if request.method == 'GET': return render_template("signin.html") netid = request.form['netid'] password = request.form['password'] remember_me = 'remember_me' in request.form registered_user = User.get_user(netid) if not registered_user: flash('NetID does not exist.') return redirect(url_for('signin')) assert isinstance(registered_user, User) if not registered_user.check_password(password): flash('Wrong password') return redirect(url_for('signin')) login_user(registered_user, remember_me) flash('Login successfully') return redirect(url_for('board'))
def test_signup_success(self): netid = "netid" password = "******" name = "test_name" data = {"netid": netid, "password": password, "name": name} r = requests.post('http://localhost:5000/api/signup/', data) self.assertEqual('OK', r.json().get('status')) self.assertEqual(200, r.status_code) try: user = r.json().get('user') self.assertTrue(user is not None) self.assertEqual(netid, user.get('netid')) self.assertTrue(user.get('password') is None) self.assertEqual(name, user.get('name')) finally: User.delete_user(netid)
def signup(): if request.method == 'GET': return render_template("signup.html") netid = request.form['netid'] password = request.form['password'] name = request.form['name'] if not netid or not password or not name: flash("Please fill all the blanks.") if User.get_user(netid): flash(u'NetID already exists!') return redirect(url_for('signin')) User.add_user(netid, password, name) flash('Sign up successfully.') return redirect(url_for('signin'))
def signup(): netid = request.form.get('netid', '') password = request.form.get('password', '') name = request.form.get('name', '') if not netid: return error(Error.EMPTY_NETID, 400) if not password: return error(Error.EMPTY_PASSWORD, 400) if not name: return error(Error.EMPTY_NAME, 400) if User.get_user(netid): return error(Error.NETID_EXISTED, 400) user = User.add_user(netid, password, name) ret = user.to_dict() ret.pop("password") return ok({"user": ret})
def signin2(): """ Used as REST API. """ netid = request.form['netid'].strip() password = request.form['password'].strip() remember_me = 'remember_me' in request.form registered_user = User.get_user(netid) if not registered_user: return error(Error.NETID_NOT_EXIST) if not registered_user.check_password(password): return error(Error.INVALID_PASSWORD) login_user(registered_user, remember_me) ret = registered_user.to_dict() ret.pop("password") return ok(ret)