def _apply_profile(_usr_name=None, _grp_name=None): """ Creates the user/group profile as required. """ usr_data = { "user_name": _usr_name, "password": "******", "email": "{}@mail.com".format(_usr_name), "group_name": get_constant("MAGPIE_ANONYMOUS_GROUP") } if use_request(cookies_or_session): if _usr_name: path = "{url}{path}".format(url=magpie_url, path=UsersAPI.path) return requests.post(path, json=usr_data) if _grp_name: path = "{url}{path}".format(url=magpie_url, path=GroupsAPI.path) data = {"group_name": _grp_name} return requests.post(path, json=data) else: if _usr_name: from magpie.api.management.user.user_utils import create_user usr_data[ 'db_session'] = cookies_or_session # back-compatibility python 2 cannot have kw after **unpack return create_user(**usr_data) if _grp_name: from magpie.api.management.group.group_utils import create_group return create_group(_grp_name, cookies_or_session)
def new_user_external(external_user_name, external_id, email, provider_name, db_session): # type: (Str, Str, Str, Str, Session) -> models.User """ Create new user with an External Identity. """ internal_user_name = external_id + "_" + provider_name internal_user_name = internal_user_name.replace(" ", "_") group_name = get_constant("MAGPIE_USERS_GROUP") create_user(internal_user_name, password=None, email=email, group_name=group_name, db_session=db_session) user = UserService.by_user_name(internal_user_name, db_session=db_session) ex_identity = models.ExternalIdentity(external_user_name=external_user_name, external_id=external_id, # noqa local_user_id=user.id, provider_name=provider_name) # noqa ax.evaluate_call(lambda: db_session.add(ex_identity), fallback=lambda: db_session.rollback(), http_error=HTTPConflict, msg_on_fail=s.Signin_POST_ConflictResponseSchema.description, content={"provider_name": str(provider_name), "internal_user_name": str(internal_user_name), "external_user_name": str(external_user_name), "external_id": str(external_id)}) user.external_identities.append(ex_identity) return user
def create_user_view(request): """ Create a new user. """ user_name = ar.get_multiformat_body(request, "user_name") email = ar.get_multiformat_body(request, "email") password = ar.get_multiformat_body(request, "password") group_name = ar.get_multiformat_body(request, "group_name") return uu.create_user(user_name, password, email, group_name, db_session=request.db)