コード例 #1
0
def register(request, username=None, password=None):
    if db.get_user(request.db_session, username):
        raise BadRequest(request,
                         error_code=ErrorCodes.Validation.UserAlreadyExists,
                         args=username)

    return add_user(request, email=username, password=password)
コード例 #2
0
def is_member_of_group(request, username, group_id):
	is_member = False
	if username is not None and group_id is not None:
		user = db.get_user(request.db_session, username)
		if db.get_group_to_user(request.db_session, group_id, user.id) is not None:
			is_member = True
	return is_member
コード例 #3
0
def is_member_of_group(request, username, group_id):
    is_member = False
    if username is not None and group_id is not None:
        user = db.get_user(request.db_session, username)
        if db.get_group_to_user(request.db_session, group_id,
                                user.id) is not None:
            is_member = True
    return is_member
コード例 #4
0
ファイル: controllers.py プロジェクト: sandeepm96/GraphSpace
def get_user_profile(request, email=None):
    """
	Get user details required to show in profile page. Generate auth_token and return.
	Return None if no email is provided.

	:param db_session: Database session.
	:param email: Email of the user. Default value is None.
	:return: User object and auth_token
	"""
    user = db.get_user(request.db_session,
                       email) if email is not None else None
    auth_token = 'Basic %s' % base64.b64encode('{0}:{1}'.format(
        user.email, user.password)) if user is not None else None
    return user, auth_token
コード例 #5
0
def add_group_member(request, group_id, member_id=None, member_email=None):
	if member_id is not None:
		user = db.get_user_by_id(request.db_session, id=member_id)
	elif member_email is not None:
		user = db.get_user(request.db_session, email=member_email)
	else:
		raise Exception("Required Parameter is missing!")
	if user is not None:
		if db.get_group_to_user(request.db_session, group_id, user.id):
			raise BadRequest(request, error_code=ErrorCodes.Validation.UserAlreadyExists, args=user.email)

		return db.add_group_to_user(request.db_session, group_id=group_id, user_id=user.id)
	else:
		raise Exception("User does not exit.")
コード例 #6
0
def add_group_member(request, group_id, member_id=None, member_email=None):
    if member_id is not None:
        user = db.get_user_by_id(request.db_session, id=member_id)
    elif member_email is not None:
        user = db.get_user(request.db_session, email=member_email)
    else:
        raise Exception("Required Parameter is missing!")
    if user is not None:
        if db.get_group_to_user(request.db_session, group_id, user.id):
            raise BadRequest(
                request,
                error_code=ErrorCodes.Validation.UserAlreadyExists,
                args=user.email)

        return db.add_group_to_user(request.db_session,
                                    group_id=group_id,
                                    user_id=user.id)
    else:
        raise Exception("User does not exit.")
コード例 #7
0
def authenticate_user(request, username=None, password=None):

    # check the username/password and return a User
    user = db.get_user(request.db_session, username)

    if user:
        hashed_pw = user.password

        #check password. if the password matches, return a
        #User object with associated information
        if bcrypt.hashpw(password, hashed_pw) == hashed_pw:
            return {
                'id': user.id,
                'user_id': user.email,
                'password': user.password,
                'admin': user.is_admin
            }
    else:
        return None
コード例 #8
0
def authenticate_user(request, username=None, password=None):

	# check the username/password and return a User
	user = db.get_user(request.db_session, username)

	if user:
		hashed_pw = user.password

		#check password. if the password matches, return a
		#User object with associated information
		if bcrypt.hashpw(password, hashed_pw) == hashed_pw:
			return {
				'id': user.id,
				'user_id': user.email,
				'password': user.password,
				'admin': user.is_admin
			}
	else:
		return None
コード例 #9
0
def get_user(request, email):
    return db.get_user(request.db_session,
                       email) if email is not None else None
コード例 #10
0
def register(request, username=None, password=None):
	if db.get_user(request.db_session, username):
		raise BadRequest(request, error_code=ErrorCodes.Validation.UserAlreadyExists, args=username)

	return add_user(request, email=username, password=password)
コード例 #11
0
def get_user(request, email):
	return db.get_user(request.db_session, email) if email is not None else None