예제 #1
0
import mailchimp

from voluptuous import Schema, Length, Required
from api.schemas import verify_to_schema, check
from api.exceptions import *
from flask import request

__check_email_format = lambda email: re.match(r".+@.+\..{2,}", email) is not None
__check_ascii = lambda s: all(ord(c) < 128 for c in s)
__check_username = lambda username: get_user(username_lower=username.lower()) is None
__check_email = lambda email: get_user_by_email(email) is None

UserSchema = Schema({
	Required("email"): check(
		([str, Length(min=4, max=128)], "Your email should be between 4 and 128 characters long."),
		([__check_email], "Someone already registered this email."),
		([__check_email_format], "Please enter a legit email.")
	),
	Required("name"): check(
		([str, Length(min=4, max=128)], "Your name should be between 4 and 128 characters long.")
	),
	Required("username"): check(
		([str, Length(min=4, max=32)], "Your username should be between 4 and 32 characters long."),
		([__check_ascii], "Please only use ASCII characters in your username."),
		([__check_username], "This username is taken, did you forget your password?")
	),
	Required("password"): check(
		([str, Length(min=4, max=64)], "Your password should be between 4 and 64 characters long."),
		([__check_ascii], "Please only use ASCII characters in your password."),
	),
	Required("type"): int,
예제 #2
0
import api.user
import bcrypt

from api.exceptions import *
from api.schemas import check, verify_to_schema

from flask import session
from voluptuous import Schema, Required, Length

UserLoginSchema = Schema({
	Required('username'): check(
		([str, Length(min=3, max=50)], "Usernames must be between 3 and 50 characters."),
	),
	Required('password'): check(
		([str, Length(min=3, max=50)], "Passwords must be between 3 and 50 characters.")
	)
})

def confirm_password(attempt, actual):
	return bcrypt.hashpw(attempt, actual) == actual

def login(username, password):
	verify_to_schema(UserLoginSchema, { "username": username, "password": password })
	user = api.user.get_user(username_lower=username.lower())
	if user is None:
		raise WebException("No user with that username exists!")
	if user.get("disabled", False):
		raise WebException("This account is disabled.")
	if confirm_password(password, user["password"]):
		if user["uid"] is not None:
			session["uid"] = user["uid"]
예제 #3
0
import api.config

from datetime import datetime

from voluptuous import Schema, Length, Required
from api.schemas import verify_to_schema, check
from api.exceptions import *
from flask import request

__check_ascii = lambda s: all(ord(c) < 128 for c in s)
__check_teamname = lambda teamname: get_team(teamname=teamname) is None

TeamSchema = Schema({
	Required("teamname"): check(
		([str, Length(min=3, max=32)], "Your teamname should be between 3 and 32 characters long."),
		([__check_ascii], "Please only use ASCII characters in your teamname."),
		([__check_teamname], "This teamname is taken.")
	),
	"school": str
}, extra=True)

max_team_users = 5

""" /api/team/create """

def create(params):
	db = api.common.db_conn()
	teamname = params["teamname"]
	if len(teamname) > 32:
		raise WebException("Team name too long!")
	params["school"] = ""