Exemplo n.º 1
0
        public object Get(GetOneCurrentUser request)
        {
            WebOneUser result = new WebOneUser();

            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/one/user/current GET ProviderId='{0}'", request.ProviderId));
                int    provId   = (request.ProviderId != 0 ? request.ProviderId : context.GetConfigIntegerValue("One-default-provider"));
                User   user     = User.FromId(context, context.UserId);
                string username = user.Email;
                try{
                    CloudUser usercloud = CloudUser.FromIdAndProvider(context, context.UserId, provId);
                    if (!String.IsNullOrEmpty(usercloud.CloudUsername))
                    {
                        username = usercloud.CloudUsername;
                    }
                }catch (Exception) {}

                OneCloudProvider oneCloud = (OneCloudProvider)CloudProvider.FromId(context, provId);
                USER_POOL        pool     = oneCloud.XmlRpc.UserGetPoolInfo();
                foreach (object u in pool.Items)
                {
                    if (u is USER_POOLUSER)
                    {
                        USER_POOLUSER oneuser = u as USER_POOLUSER;
                        if (oneuser.NAME == username)
                        {
                            result = new WebOneUser {
                                Id = oneuser.ID, Name = oneuser.NAME, Password = oneuser.PASSWORD, AuthDriver = oneuser.AUTH_DRIVER
                            };
                            break;
                        }
                    }
                }

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
Exemplo n.º 2
0
        public void EndDelegate()
        {
            CloudUser cuser = CloudUser.FromIdAndProvider(context, context.UserId, oneCloud.Id);

            cloudusername = cuser.CloudUsername;
        }
Exemplo n.º 3
0
        public object Post(CreateOneUser request)
        {
            WebOneUser result;
            var        context = TepWebContext.GetWebContext(PagePrivileges.UserView);

            try {
                context.Open();

                int    provId   = (request.ProviderId != 0 ? request.ProviderId : context.GetConfigIntegerValue("One-default-provider"));
                User   user     = User.FromId(context, context.UserId);
                string username = user.Email;
                try{
                    CloudUser usercloud = CloudUser.FromIdAndProvider(context, context.UserId, provId);
                    if (!String.IsNullOrEmpty(usercloud.CloudUsername))
                    {
                        username = usercloud.CloudUsername;
                    }
                }catch (Exception) {}

                OneCloudProvider oneCloud = (OneCloudProvider)CloudProvider.FromId(context, provId);

                //create user
                int  id      = oneCloud.XmlRpc.UserAllocate(username, request.Password, (String.IsNullOrEmpty(request.AuthDriver) ? "x509" : request.AuthDriver));
                USER oneuser = oneCloud.XmlRpc.UserGetInfo(id);

                context.LogInfo(this, string.Format("/one/user POST ProviderId='{0}',Id='{1}'", request.ProviderId, id));

                List <KeyValuePair <string, string> > templatePairs = new List <KeyValuePair <string, string> >();
                templatePairs.Add(new KeyValuePair <string, string>("USERNAME", username));
                templatePairs.Add(new KeyValuePair <string, string>("VM_USERNAME", user.Username));

                try{
                    GithubProfile github = GithubProfile.FromId(context, user.Id);
                    if (!String.IsNullOrEmpty(github.Name))
                    {
                        templatePairs.Add(new KeyValuePair <string, string>("GITHUB_USERNAME", github.Name));
                    }
                    if (!String.IsNullOrEmpty(github.Email))
                    {
                        templatePairs.Add(new KeyValuePair <string, string>("GITHUB_EMAIL", github.Email));
                    }
                    if (!String.IsNullOrEmpty(github.Token))
                    {
                        templatePairs.Add(new KeyValuePair <string, string>("GITHUB_TOKEN", github.Token));
                    }
                }catch (Exception) {}

                //update user template
                string templateUser = CreateTemplate((XmlNode[])oneuser.TEMPLATE, templatePairs);
                if (!oneCloud.XmlRpc.UserUpdate(id, templateUser))
                {
                    throw new Exception("Error during update of user");
                }

                //add user to group GEP
                oneCloud.XmlRpc.UserUpdateGroup(id, context.GetConfigIntegerValue("One-GEP-grpID"));

                result = new WebOneUser {
                    Id = oneuser.ID, Name = oneuser.NAME, Password = oneuser.PASSWORD, AuthDriver = oneuser.AUTH_DRIVER
                };
                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
Exemplo n.º 4
0
        public void StartDelegate(int idusr)
        {
            CloudUser cuser = CloudUser.FromIdAndProvider(context, idusr, oneCloud.Id);

            cloudusername = cuser.CloudUsername;
        }