public ActionResult ChangeEmail(ChangeEmail model)
        {
            if (ModelState.IsValid)
            {
                string          connection  = ConfigurationManager.AppSettings["InternalAPIURL"];
                var             ctx         = Request.GetOwinContext();
                ClaimsPrincipal user        = ctx.Authentication.User;
                string          accessToken = user.Claims.FirstOrDefault(x => x.Type == "AccessToken").Value;
                Guid            userID      = new Guid(user.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value);

                EditUserRequest request = new EditUserRequest(connection, accessToken, userID);
                request.Email    = model.Email;
                request.Password = model.password1;

                EditUserResponse response = request.Send();

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    TempData["Success"] = "You have successfully updated your email. An email has been sent to the new address with instructions on how to verify the address change.";
                    return(RedirectToAction("Index", "Account"));
                }
                else
                {
                    TempData["Errors"] = "There was an error processing your request. Please try again.";
                    return(View(model));
                }
            }
            else
            {
                return(View(model));
            }
        }
예제 #2
0
            public void ChangeEmail()
            {
                EditUserRequest request = new EditUserRequest(connection, testToken, testUser);

                request.Email    = "*****@*****.**";
                request.Password = "******";

                EditUserResponse response = request.Send();

                Assert.AreEqual(response.StatusCode, System.Net.HttpStatusCode.OK);
            }
예제 #3
0
            public void EditUser()
            {
                EditUserRequest request = new EditUserRequest(connection, testToken, testUser);

                request.FirstName = "Knar2";
                request.LastName  = "Lhe";
                request.Nicknane  = "Knar66";

                EditUserResponse response = request.Send();

                Assert.AreEqual(response.StatusCode, System.Net.HttpStatusCode.OK);
            }
        public ActionResult EditInfo(EditInfo model)
        {
            if (ModelState.IsValid)
            {
                string         connection      = ConfigurationManager.AppSettings["InternalAPIURL"];
                var            ctx             = Request.GetOwinContext();
                ClaimsIdentity identity        = new ClaimsIdentity(Request.GetOwinContext().Authentication.User.Identity);
                string         accessToken     = identity.FindFirst("AccessToken").Value;
                Guid           userID          = new Guid(identity.FindFirst(ClaimTypes.NameIdentifier).Value);
                string         currentUserName = identity.FindFirst(ClaimTypes.Name).Value;

                EditUserRequest request = new EditUserRequest(connection, accessToken, userID);
                request.FirstName = model.FirstName;
                request.LastName  = model.LastName;
                request.Nicknane  = model.Nicknane;

                EditUserResponse response = request.Send();

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    //TODO: If Nickname is changed, change it in the user claim
                    if (request.Nicknane != currentUserName)
                    {
                        identity.RemoveClaim(identity.FindFirst(ClaimTypes.Name));
                        identity.AddClaim(new Claim(ClaimTypes.Name, request.Nicknane));

                        var authenticationManager = HttpContext.GetOwinContext().Authentication;
                        authenticationManager.SignOut();

                        AuthenticationProperties properties = new AuthenticationProperties {
                            IsPersistent = Convert.ToBoolean(identity.FindFirst(ClaimTypes.IsPersistent).Value)
                        };
                        authenticationManager.SignIn(properties, identity);

                        ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(identity);
                        HttpContext.User = claimsPrincipal;
                    }

                    TempData["Success"] = "You have successfully updated your info";
                    return(RedirectToAction("Index", "Account"));
                }
                else
                {
                    TempData["Errors"] = "There was an error processing your request. Please try again.";
                    return(View(model));
                }
            }
            else
            {
                return(View(model));
            }
        }
예제 #5
0
        public EditUserResponse EditUser(EditUserRequest request)
        {
            EditUserResponse response = new EditUserResponse();

            AuthToken authToken = null;

            try
            {
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.AuthToken, "Auth Token");
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.AntiForgeryToken, "Anti Forgery Token");
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.Username, "Username");

                Common.Helpers.ValidationHelper.ValidateRequiredField(request.FirstName, "First Name");
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.LastName, "Last Name");
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.Username, "User Name");
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.EmailAddress, "Email Address");

                Common.Helpers.ValidationHelper.ValidateStringLength(request.FirstName, "First Name", Constants.MaxNameLength);
                Common.Helpers.ValidationHelper.ValidateStringLength(request.LastName, "Last Name", Constants.MaxNameLength);
                Common.Helpers.ValidationHelper.ValidateStringLength(request.Username, "User Name", Constants.MaxUsernameLength);
                Common.Helpers.ValidationHelper.ValidateStringLength(request.EmailAddress, "Email Address", Constants.MaxUsernameLength);

                Common.Helpers.ValidationHelper.ValidateEmailAddress(request.EmailAddress);

                if (!UserController.ValidateSession(request.AuthToken, out authToken))
                {
                    throw new AuthenticationException("Authentication failed.");
                }

                UserController.ValidateAntiForgeryToken(request.AntiForgeryToken, authToken);

                UserController.UpdateUser(request.Username, request.FirstName, request.LastName, request.EmailAddress, authToken);
            }
            catch (AuthenticationException ex)
            {
                throw new WebFaultException <string>(ex.Message, System.Net.HttpStatusCode.BadRequest);
            }
            catch (Common.Exceptions.ValidationException ex)
            {
                throw new WebFaultException <string>(ex.Message, System.Net.HttpStatusCode.BadRequest);
            }
            catch (Exception ex)
            {
                ExceptionHelper.Log(ex, authToken == null ? null : authToken.Username);
                throw new WebFaultException <string>("An unknown error has occurred.", System.Net.HttpStatusCode.InternalServerError);
            }

            return(response);
        }
예제 #6
0
        public EditUserResponse Edit(EditUserRequest request)
        {
            try
            {
                var response = new EditUserResponse();
                var bc       = new UsersComponent();
                bc.Edit(request.User);

                return(response);
            }
            catch (Exception ex)
            {
                var httpError = new HttpResponseMessage()
                {
                    StatusCode   = (HttpStatusCode)422,
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(httpError);
            }
        }
예제 #7
0
        public EditUserResponse EditUser(EditUserRequest request)
        {
            EditUserResponse response = new EditUserResponse();

            AuthToken authToken = null;

            try
            {
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.AuthToken, "Auth Token");
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.AntiForgeryToken, "Anti Forgery Token");
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.Username, "Username");

                Common.Helpers.ValidationHelper.ValidateRequiredField(request.FirstName, "First Name");
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.LastName, "Last Name");
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.Username, "User Name");
                Common.Helpers.ValidationHelper.ValidateRequiredField(request.EmailAddress, "Email Address");

                Common.Helpers.ValidationHelper.ValidateStringLength(request.FirstName, "First Name", Constants.MaxNameLength);
                Common.Helpers.ValidationHelper.ValidateStringLength(request.LastName, "Last Name", Constants.MaxNameLength);
                Common.Helpers.ValidationHelper.ValidateStringLength(request.Username, "User Name", Constants.MaxUsernameLength);
                Common.Helpers.ValidationHelper.ValidateStringLength(request.EmailAddress, "Email Address", Constants.MaxUsernameLength);

                Common.Helpers.ValidationHelper.ValidateEmailAddress(request.EmailAddress);

                if (!UserController.ValidateSession(request.AuthToken, out authToken))
                {
                    throw new AuthenticationException("Authentication failed.");
                }

                UserController.ValidateAntiForgeryToken(request.AntiForgeryToken, authToken);

                UserController.UpdateUser(request.Username, request.FirstName, request.LastName, request.EmailAddress, authToken);
            }
            catch (AuthenticationException ex)
            {
                throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.BadRequest);
            }
            catch (Common.Exceptions.ValidationException ex)
            {
                throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.BadRequest);
            }
            catch (Exception ex)
            {
                ExceptionHelper.Log(ex, authToken == null ? null : authToken.Username);
                throw new WebFaultException<string>("An unknown error has occurred.", System.Net.HttpStatusCode.InternalServerError);
            }

            return response;
        }