コード例 #1
0
        /// <summary>
        /// This method changes user's username after authentication.
        /// </summary>
        /// <param name="model">A ChangeUsername instance for the ChangeUsername function.</param>
        public async Task <IActionResult> ChangeUsername([FromBody] ChangeUsername model)
        {
            string username = User.FindFirst(ClaimTypes.Name)?.Value;


            var user = await userManager.FindByNameAsync(username);

            if (user == null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new Response {
                    Status = "Error", Message = "User not exists!"
                }));
            }

            IdentityResult result = await userManager.SetUserNameAsync(user, model.NewUsername);

            if (result.Succeeded)
            {
                return(Ok(new Response {
                    Status = "Success", Message = "username changed successfully!"
                }));
            }
            return(StatusCode(StatusCodes.Status500InternalServerError, new Response {
                Status = "Error", Message = "password change fail!"
            }));;
        }
コード例 #2
0
 public ViewResult ChangeUsername(ChangeUsername uname)
 {
     if (!HttpContext.Request.Cookies.ContainsKey("Logined"))
     {
         return(View("Login"));
     }
     if (ModelState.IsValid)
     {
         if (userDB.IsUsernameExist(uname.Username, currentUser.UserID))
         {
             ModelState.AddModelError("Username", "This Username already used by other user, try another one");
             return(View());
         }
         else
         {
             postDB.UpdateUsernameInDB(currentUser.Username, uname.Username);
             currentUser.Username = uname.Username;
             userDB.UpdateUsernameInDB(currentUser);
             return(View("Profile", currentUser));
         }
     }
     else
     {
         return(View());
     }
 }
コード例 #3
0
        public static void OnPacket(object pack)
        {
            Debug.Log("OnPacket_ChangeUsername");
            ChangeUsername changeUsername = pack as ChangeUsername;

            Gamedata.me.userinfo.Username = changeUsername.Username;
            PanelManager.me.RefreshAll();
        }
コード例 #4
0
        public static void OnPacket(Client client, object pack)
        {
            ReqChangeUsername req = pack as ReqChangeUsername;
            ChangeUsername    rsp = new ChangeUsername();

            rsp.Userid   = req.Userid;
            rsp.Username = req.Username;
            client.Send(rsp);
            UserSystem.me.ChangeUsername(req.Userid, req.Username);
            return;
        }
コード例 #5
0
 private void OnEditUserName(object sender, EventArgs e)
 {
     try
     {
         var username = new ChangeUsername(this);
         Task.Run(async() => await PopupNavigation.Instance.PushAsync(username));
     }
     catch (Exception ex)
     {
     }
 }
コード例 #6
0
 /* Take commands as dependencies.
  * This may get awkward once a constructor
  * takes lots of commands... and you may want to consider
  * using a command dispatcher.
  *
  * Good thing is, we get rid of Service classes,
  * which are basically logic dumpsters.
  *
  * Let the controller actions follow an Accept-Delegate-Reply pattern.
  */
 public UsersController(
     GetUsers getUsers,
     ChangeEmail changeEmail,
     ChangeUsername changeUsername,
     IDistributedCache cache
     )
 {
     this.getUsers       = getUsers;
     this.changeEmail    = changeEmail;
     this.changeUsername = changeUsername;
     this.cache          = cache;
 }
コード例 #7
0
        public async Task <ActionResult> ChangeUsername(ChangeUsername model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            user.UserName = model.UserName;
            var result = await UserManager.UpdateAsync(user);

            if (user != null)
            {
                await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
            }
            return(RedirectToAction("Index", new { Message = ManageMessageId.ChangeUsernameSuccess }));
        }
        protected static void Initialize()
        {
            InitializeBus();
            ExceptionHandlerMock = new Mock <IExceptionHandler>();
            Handler               = new Handler(ExceptionHandlerMock.Object);
            UserServiceMock       = new Mock <IUserService>();
            ChangeUserNameHandler = new ChangeUserNameHandler(Handler,
                                                              BusClientMock.Object, UserServiceMock.Object);

            Command = new ChangeUsername
            {
                Name    = "newName",
                UserId  = "userId",
                Request = new Request
                {
                    Id        = Guid.NewGuid(),
                    CreatedAt = DateTime.Now,
                    Culture   = "en-US",
                    Name      = "name",
                    Origin    = "collectively",
                    Resource  = "resource"
                }
            };
            User = new User("userId", "*****@*****.**", Roles.User, "collectively");
            UserServiceMock
            .Setup(x => x.ChangeNameAsync(Moq.It.IsAny <string>(), Moq.It.IsAny <string>()))
            .Callback(() =>
            {
                User.SetName(Command.Name);
                User.Activate();
            })
            .Returns(Task.CompletedTask);
            UserServiceMock
            .Setup(x => x.GetAsync(Command.UserId))
            .ReturnsAsync(User);
        }
コード例 #9
0
 public async Task HandleAsync(ChangeUsername command)
 => await CreateForAuthenticatedUserAsync(command);
コード例 #10
0
ファイル: Account.cs プロジェクト: eisenschenk/gamecollection
 public IEnumerable <IEvent> On(ChangeUsername command)
 {
     yield return(new UsernameChanged(command.ID, command.NewUsername));
 }