예제 #1
0
        public bool ChangeUsername(int userId, ChangeUsernameRequest request)
        {
            var user = Fetch(userId);

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

            //verify its not already being used
            var exists = _context.Users
                         .Where(u => u.Username == request.username)
                         .FirstOrDefault(e => e.Id != userId);

            if (exists != null)
            {
                return(false);
            }

            user.Username = request.username;

            _context.Users.Update(user);
            _context.SaveChanges();

            return(true);
        }
예제 #2
0
        public async Task <IActionResult> ChangeUsername([FromBody] ChangeUsernameRequest request)
        {
            var    userId      = (this.HttpContext.Items["User"] as EntityUser).Id;
            string newusername = await this._userService.ChangeUsername(userId, request.Username);

            return(Ok(newusername));
        }
예제 #3
0
        public async Task <IActionResult> ChangeUsername(ChangeUsernameRequest request)
        {
            var response = await mediator.Send(request);

            Log.Information($"User #{HttpContext.GetCurrentUserId()} changed their username to: {request.NewUsername}");

            return(this.CreateResponse(response));
        }
예제 #4
0
        public async Task <IActionResult> ChangeUsername(ChangeUsernameRequest request)
        {
            var response = await mediator.Send(request);

            logger.LogResponse($"User #{HttpContext.GetCurrentUserId()} changed username to: {request.NewUsername}",
                               response.Error);

            return(this.CreateResponse(response));
        }
예제 #5
0
        public ActionResult ChangeUsername([FromBody] ChangeUsernameRequest request)
        {
            var deleted = _userService.ChangeUsername(Convert.ToInt32(User.Identity.Name), request);

            if (!deleted)
            {
                return(BadRequest(new { message = "Username already exists." }));
            }
            return(Ok());
        }
예제 #6
0
        public async Task <bool> UpdateUsername([FromBody] ChangeUsernameRequest request)
        {
            var user = await _authenticatedUser.GetUserAsync();

            if (user.VerifyPassword(request.Password) == null)
            {
                throw new HttpException(HttpStatusCode.Unauthorized, "Incorrect password.");
            }

            user.Username = request.Username;
            await user.SaveAsync();

            return(true);
        }
예제 #7
0
        //Change Username 
        public async Task<LoginUpdateInfo> GetChangeUsername (ChangeUsernameRequest username){

            try{
                var test2 =  await service.ChangeUsername(username, BearerToken);
                    return test2;
            }catch(ApiException apie){
                Insights.Report(apie, ReportSeverity.Error);
                throw;
            }
        }