public IActionResult EditName([FromBody] ChangeUserNameRequest request)
        {
            var userId = Request.GetUserId();

            _userEditFacade.EditName(userId, request.UserName);
            return(Ok());
        }
Exemplo n.º 2
0
        public async Task ChangeUserName_Should_Fail_If_Change_Fails()
        {
            var signInManagerMock = new Mock <FakeSignInManager>();
            var userManagerMock   = new Mock <FakeUserManager>();

            userManagerMock
            .Setup(x => x.FindByNameAsync("test"))
            .ReturnsAsync(new EmbyStatUser {
                UserName = "******"
            });
            userManagerMock
            .Setup(x => x.SetUserNameAsync(It.IsAny <EmbyStatUser>(), "test2"))
            .ReturnsAsync(IdentityResult.Failed(new IdentityError()));

            var settingsServiceMock = new Mock <ISettingsService>();
            var tokenHandler        = new Mock <JwtSecurityTokenHandler>();

            var accountService = new AccountService(signInManagerMock.Object, userManagerMock.Object,
                                                    settingsServiceMock.Object, tokenHandler.Object);

            var request = new ChangeUserNameRequest
            {
                UserName    = "******",
                NewUserName = "******"
            };
            var result = await accountService.ChangeUserName(request);

            result.Should().BeFalse();

            userManagerMock.Verify(x => x.FindByNameAsync("test"), Times.Once);
            userManagerMock.Verify(x => x.SetUserNameAsync(It.IsAny <EmbyStatUser>(), "test2"), Times.Once);
        }
Exemplo n.º 3
0
        public async Task ChangeUserName_Should_Fail_If_User_Is_Unknown()
        {
            var signInManagerMock = new Mock <FakeSignInManager>();
            var userManagerMock   = new Mock <FakeUserManager>();

            userManagerMock
            .Setup(x => x.FindByNameAsync("test"))
            .ReturnsAsync((EmbyStatUser)null);

            var settingsServiceMock = new Mock <ISettingsService>();
            var tokenHandler        = new Mock <JwtSecurityTokenHandler>();

            var accountService = new AccountService(signInManagerMock.Object, userManagerMock.Object,
                                                    settingsServiceMock.Object, tokenHandler.Object);

            var request = new ChangeUserNameRequest
            {
                UserName    = "******",
                NewUserName = "******"
            };
            var result = await accountService.ChangeUserName(request);

            result.Should().BeFalse();

            userManagerMock.Verify(x => x.FindByNameAsync("test"), Times.Once);
            userManagerMock.Verify(x => x.SetUserNameAsync(It.IsAny <EmbyStatUser>(), It.IsAny <string>()), Times.Never);
        }
Exemplo n.º 4
0
        public async Task <bool> ChangeUserName(ChangeUserNameRequest request)
        {
            var user = await _userManager.FindByNameAsync(request.UserName);

            if (user == null)
            {
                return(false);
            }

            var result = await _userManager.SetUserNameAsync(user, request.NewUserName);

            if (!result.Succeeded)
            {
                _logger.Warn($"Password update for ${user.UserName} failed with following message \n ${result.Errors.Select(x => x.Code + " - " + x.Description + "\n")}");
            }

            return(result.Succeeded);
        }
Exemplo n.º 5
0
        public async Task <ChangeUserNameResponse> RequestUserNameChange(ChangeUserNameRequest request)
        {
            // Get the user
            var user = await userManager.FindByIdAsync(request.UserId);

            // Validate the sent password
            if (!await userManager.CheckPasswordAsync(user, request.Password))
            {
                return(new ChangeUserNameResponse(false, 400, "Incorrect password"));
            }

            // Generate verification code
            var verificationCode = await userManager.GenerateChangePhoneNumberTokenAsync(user, user.PhoneNumber);

            // Send the verification code email
            await messager.SendEmailAsync(user.Email, "Username Change", string.Format("You have requested to change your account email, to complete, please input the following code: {0}", verificationCode));

            return(new ChangeUserNameResponse(true, 200, "A verification code has been sent to your email"));
        }
        public async Task <IActionResult> ChangeUserName([FromBody] ChangeUserNameRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            if (user == null)
            {
                return(BadRequest());
            }

            user.UserName = request.NewUserName;
            var result = await _userManager.UpdateAsync(user);

            if (!result.Succeeded)
            {
                return(BadRequest());
            }

            return(await GetToken(user));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> ChangeUsername([FromBody] ChangeUserNameRequest request)
        {
            var result = await _accountService.ChangeUserName(request);

            return(Ok(result));
        }
Exemplo n.º 8
0
        public override async Task ChangeUserName(ChangeUserNameRequest request, IServerStreamWriter <ChangeUserNameReply> responseStream, ServerCallContext context)
        {
            var session = await context.GetSession();

            if (session == null)
            {
                await responseStream.WriteAsync(new ChangeUserNameReply()
                {
                    Code = ErrorCode.LostSession
                });

                return;
            }

            //유저 아이디 영문과 숫자 조합만 허용
            //if (Regex.IsMatch(request.UserName, @"^[a-zA-Z0-9]+$") == false)
            if (Regex.IsMatch(request.UserName, @"^[a-zA-Z0-9가-힣]*$") == false)
            {
                Log.Error($"ChangeUserName error {request.UserName}");
                await responseStream.WriteAsync(new ChangeUserNameReply()
                {
                    Code = ErrorCode.WrongLetters
                });

                return;
            }

            if (request.UserName.Length < 2 || request.UserName.Length > 10)
            {
                Log.Error($"ChangeUserName error {request.UserName}");
                await responseStream.WriteAsync(new ChangeUserNameReply()
                {
                    Code = ErrorCode.WrongLetters
                });

                return;
            }

            if (request.UserName.IsLetterOrDigit() == false)
            {
                Log.Error($"ChangeUserName error {request.UserName}");
                await responseStream.WriteAsync(new ChangeUserNameReply()
                {
                    Code = ErrorCode.WrongLetters
                });

                return;
            }

            if (await BannedWordFilter.Check(request.UserName) == false)
            {
                Log.Error($"ChangeUserName error {request.UserName}");
                await responseStream.WriteAsync(new ChangeUserNameReply()
                {
                    Code = ErrorCode.WrongLetters
                });

                return;
            }

            // 유저 디비 업데이트
            var ret = await MemberQuery.UpdateMember(session.member_no, request.UserName);

            if (ret != ErrorCode.Success)
            {
                await responseStream.WriteAsync(new ChangeUserNameReply()
                {
                    Code = ret
                });

                return;
            }


            // 세션 캐시 업데이트
            await Session.UpdateSessionLock(session.session_id, delegate(Session s) { s.user_name = request.UserName; });

            await responseStream.WriteAsync(new ChangeUserNameReply()
            {
                Code = ErrorCode.Success
            });
        }