Пример #1
0
func (p urlParams) user(paramPosition int, users interfaces.UserService) (ct.UserId, types.Error) {
	user, err := ct.ParseUserId(p.params[paramPosition].Value)
	if err != nil {
		return ct.UserId{}, types.BadParamError(err.Error())
	}
	if users != nil {
		exists, err := users.UserExists(user, user)
		if err != nil {
			return ct.UserId{}, err
		}
		if !exists {
			return ct.UserId{}, types.NotFoundError("user '" + user.String() + "' doesn't exist")
		}
	}
	return user, nil
}
Пример #2
0
func readAccessToken(
	userService interfaces.UserService,
	tokenService interfaces.TokenService,
	req *http.Request,
) (ct.UserId, types.Error) {
	token := req.URL.Query().Get("access_token")
	if token == "" {
		return ct.UserId{}, types.DefaultMissingTokenError
	}
	info, err := tokenService.ParseAccessToken(token)
	if err != nil {
		return ct.UserId{}, types.DefaultUnknownTokenError
	}
	exists, err := userService.UserExists(info.UserId(), info.UserId())
	if err != nil {
		return ct.UserId{}, types.DefaultUnknownTokenError
	}
	if !exists {
		return ct.UserId{}, types.DefaultUnknownTokenError
	}
	return info.UserId(), nil
}