Beispiel #1
0
        public ActionResult MyAccount(SiriusAccountModel model)
        {
            var updateMessage = new SettingUpdateMessage();

            if (ModelState.IsValid)
            {
                var userId = User.Identity.GetUserId();
                var user   = userManager.FindById(userId);

                model.ReceiveEmail = user.ReceiveEmail != null && (bool)user.ReceiveEmail;
                model.ReceiveSms   = user.ReceiveSms != null && (bool)user.ReceiveSms;
                model.Phone        = user.Phone;

                var validUser = userManager.ValidateAndReturnUser(user.UserName, model.OldPassword);
                if (validUser != null)
                {
                    var succeed = userManager.UpdatePassword(validUser.Id, model.Password);
                    if (succeed)
                    {
                        updateMessage.Type        = AccountMessageType.Success;
                        updateMessage.MessageText = "Uppdaterade lösenordet";
                    }
                    else
                    {
                        updateMessage.Type        = AccountMessageType.Error;
                        updateMessage.MessageText = "Lösenordet uppdaterades inte";
                    }
                }
                else
                {
                    updateMessage.Type        = AccountMessageType.Error;
                    updateMessage.MessageText = "Felaktigt lösenord";
                }
                model.Message = updateMessage;
                return(View(model));
            }

            updateMessage.Type        = AccountMessageType.Error;
            updateMessage.MessageText = "Lösenordet uppdaterades inte";
            model.Message             = updateMessage;
            return(View(model));
        }
Beispiel #2
0
        public ActionResult UpdateSettings(bool receiveEmail, bool receiveSms, string phone)
        {
            var userId = User.Identity.GetUserId();
            var user   = userManager.FindById(userId);

            var updateMessage = new SettingUpdateMessage();

            if (user != null)
            {
                user.ReceiveEmail = receiveEmail;
                user.ReceiveSms   = receiveSms;
                user.Phone        = phone;
                userManager.Update(user);
                updateMessage.Type        = "Success";
                updateMessage.MessageText = "Uppdaterade inställningar";
                return(Json(updateMessage, JsonRequestBehavior.AllowGet));
            }

            updateMessage.Type        = "Error";
            updateMessage.MessageText = "Oväntat fel";
            return(Json(updateMessage, JsonRequestBehavior.AllowGet));
        }