Example #1
0
def add_client():

	data = request.json
	if not data:
		abort(400)

	firstname = data.get('firstname')
	lastname = data.get('lastname')
	email = data.get('email')
	password = data.get('password')

	# todo validate email/password

	if not email or not password or not firstname or not lastname:
		abort(400)

	client = app.db['clients'].find_one({'email': email})
	if client:
		abort(400, 'account already exists')

	payload = {'firstname': firstname,
			   'lastname': lastname,
			   'email': email,
			   'password': encrypt_password(password)}

	payload['_created'] = payload['_updated'] = datetime.utcnow().replace(microsecond=0).replace(tzinfo=pytz.utc)

	clientId = app.db['clients'].insert(payload)

	token_resp = generate_token(str(clientId))
	return jsonify(token_resp)
Example #2
0
 def set_user(self, username, seed, password):
     self.data["users"][username] = encrypt_password(seed, password)