def put(self, user_id, user): """Modify this user. :param user_id: Unique id to identify the user. :param user: A user within the request body. """ current_user = users_api.user_get(request.current_user_id) # Only owners and superadmins are allowed to modify users. if request.current_user_id != user_id \ and not current_user.is_superuser: abort(403, _("You are not allowed to update this user.")) # Strip out values that you're not allowed to change. user_dict = user.as_dict(omit_unset=True) if not current_user.is_superuser: # Only superuser may create superusers or modify login permissions. if 'enable_login' in six.iterkeys(user_dict): del user_dict['enable_login'] if 'is_superuser' in six.iterkeys(user_dict): del user_dict['is_superuser'] updated_user = users_api.user_update(user_id, user_dict) return wmodels.User.from_db_model(updated_user)
def save_authorization_code(self, client_id, code, request, *args, **kwargs): """Save the code to the storage and remove the state as it is persisted in the "code" argument """ openid = request._params["openid.claimed_id"] email = request._params["openid.sreg.email"] full_name = request._params["openid.sreg.fullname"] last_login = datetime.datetime.now(pytz.utc) user = user_api.user_get_by_openid(openid) user_dict = {"full_name": full_name, "email": email, "last_login": last_login} if not user: user_dict.update({"openid": openid}) user = user_api.user_create(user_dict) else: user = user_api.user_update(user.id, user_dict) # def save_authorization_code(self, authorization_code, user_id): values = { "code": code["code"], "state": code["state"], "user_id": user.id, "expires_in": CONF.oauth.authorization_code_ttl } auth_api.authorization_code_save(values)
def put(self, user_id, user): """Modify this user. Admin users can edit the user details of any user, authenticated users can only modify their own details. Example:: curl https://my.example.org/api/v1/users/21 -X PUT \\ -H 'Authorization: Bearer MY_ACCESS_TOKEN' \\ -H 'Content-Type: application/json;charset=UTF-8' \\ --data-binary '{"email":"*****@*****.**"}' :param user_id: Unique id to identify the user. :param user: A user within the request body. """ current_user = users_api.user_get(request.current_user_id) # Only owners and superadmins are allowed to modify users. if request.current_user_id != user_id \ and not current_user.is_superuser: abort(403, _("You are not allowed to update this user.")) # Strip out values that you're not allowed to change. user_dict = user.as_dict(omit_unset=True) if not current_user.is_superuser: # Only superuser may create superusers or modify login permissions. if 'enable_login' in six.iterkeys(user_dict): del user_dict['enable_login'] if 'is_superuser' in six.iterkeys(user_dict): del user_dict['is_superuser'] filter_non_public = True if user_id == request.current_user_id: filter_non_public = False updated_user = users_api.user_update( user_id, user_dict, filter_non_public) return wmodels.User.from_db_model(updated_user)