コード例 #1
0
        public async Task <CheckUserNameResponse> CheckUserNameAsync(CheckUserNameRequest request)
        {
            var response = new CheckUserNameResponse();

            var userEntity = await _userManager.FindByNameAsync(request.UserName);

            response.IsUserNameAvailable = userEntity == null;
            response.StatusCode          = (int)HttpStatusCode.OK;

            return(response);
        }
コード例 #2
0
        public void UserNameIsAvailableShouldBeFalseIfUserAlreadyExists()
        {
            UserManager           userProxy = new UserManager();
            string                userName  = "******";
            CheckUserNameResponse result    = userProxy.IsUserNameAvailable(userName);

            Expect.IsTrue((bool)result.Data);

            User user = User.Create(userName);

            result = userProxy.IsUserNameAvailable(userName);
            Expect.IsFalse((bool)result.Data);
        }
コード例 #3
0
 /// <summary>
 /// Establishes the means by which the client will
 /// communicate securely with the server.  Creates
 /// a machine account for the client; used primarily
 /// for .Net client assemblies using CoreClient
 /// </summary>
 /// <param name="client"></param>
 /// <returns>A CoreServiceResponse message detailing success or failure.</returns>
 public virtual CoreServiceResponse RegisterClient(Client client)
 {
     try
     {
         Args.ThrowIfNullOrEmpty(client?.Secret, nameof(client.Secret));
         Args.ThrowIfNullOrEmpty(client?.ServerHost, nameof(client.ServerHost));
         Args.ThrowIfNull(client?.Machine, nameof(client.Machine));
         Args.ThrowIf(client.Port <= 0, "Server Port not specified");
         IUserManager mgr = (IUserManager)UserManager.Clone();
         mgr.HttpContext = HttpContext;
         string clientName = client.ToString();
         CoreServiceResponse   response      = new CoreServiceResponse();
         CheckUserNameResponse checkUserName = mgr.IsUserNameAvailable(clientName);
         if (!(bool)checkUserName.Data) // already exists
         {
             response.Success = true;
             response.Message = "Already registered";
         }
         else
         {
             SignUpResponse signupResponse = mgr.SignUp(client.GetPseudoEmail(), clientName, client.Secret.Sha1(), false);
             if (!signupResponse.Success)
             {
                 throw new Exception(response.Message);
             }
             Machine machine = ApplicationRegistrationRepository.GetOneMachineWhere(m => m.Name == client.MachineName);
             client   = ApplicationRegistrationRepository.GetOneClientWhere(c => c.MachineId == machine.Id && c.MachineName == client.MachineName && c.ApplicationName == client.ApplicationName && c.ServerHost == client.ServerHost && c.Port == client.Port);
             response = new CoreServiceResponse {
                 Success = true, Data = client.ToDynamicData().ToJson()
             };
         }
         return(response);
     }
     catch (Exception ex)
     {
         return(HandleException(ex, nameof(ApplicationRegistrationService.RegisterClient)));
     }
 }