public void ChangeProfileShouldRedirectCorrectlyWhenErroring()
        {
            //ARRANGE
            var model = new ChangeProfile {
                Day = 13, Month = 09, Year = 1984, Answer = "test"
            };
            const string userName = "******";
            var          user     = new User();

            var userMock = new Mock <IPrincipal>();

            userMock
            .Setup(p => p.Identity.Name)
            .Returns(userName);

            var context = new Mock <HttpContextBase>();

            context
            .Setup(ctx => ctx.User)
            .Returns(userMock.Object);

            var controllerContext = new Mock <ControllerContext>();

            controllerContext
            .Setup(con => con.HttpContext)
            .Returns(context.Object);

            var userLogic = new Mock <IUserLogic>();

            userLogic
            .Setup(x => x.FindByName(userName))
            .Returns(user)
            .Verifiable("Should get the user.");

            userLogic
            .Setup(x => x.Update(user))
            .Returns(false)
            .Verifiable("Should create the user");

            var encryptionHelper = new Mock <IEncryptionHelper>();

            encryptionHelper
            .Setup(x => x.EncryptString("test", "JellyTank"))
            .Verifiable();

            var controller = new ProfileController(userLogic.Object, null, encryptionHelper.Object)
            {
                ControllerContext = controllerContext.Object
            };

            //ACT
            var result = controller.ChangeProfile(model) as ViewResult;

            //ASSERT
            userLogic.Verify();
            encryptionHelper.Verify();

            Assert.NotNull(result);
            Assert.AreEqual("ChangeProfile", result.ViewName);
        }
Example #2
0
        public IActionResult ChangeProfile(ChangeProfile model)
        {
            CountScore();
            if (ModelState.IsValid)
            {
                var changeUser = db.Users.FirstOrDefault(u => u.Id == currentProfile.Id);
                if (changeUser != null)
                {
                    changeUser.Name     = model.Name;
                    changeUser.Nickname = model.Nickname;
                    changeUser.Email    = model.Email;
                    changeUser.Password = model.Password ?? changeUser.Password;
                    db.SaveChanges();
                    if (currentProfile.Nickname != model.Nickname)
                    {
                        return(RedirectToAction("Login", "Account"));
                    }
                    else
                    {
                        return(RedirectToAction("Lots", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Ошибка авторизации");
                }
            }

            return(ChangeProfile());
        }
Example #3
0
 public ActionResult EditUserProfile([Bind(Include = "Name, Age,Nationality, PhoneNumber, Email, NativeLanguage, FluentLanguage, InterestedLanguage")] ChangeProfile changeProfile, HttpPostedFileBase photo)
 {
     if (ModelState.IsValid)
     {
         if (photo != null && photo.ContentLength > 0)
         {
             try
             {
                 string path = Path.Combine(Server.MapPath("~/UploadedFiles/"), Path.GetFileName(photo.FileName));
                 photo.SaveAs(path);
                 changeProfile.Photo           = "/UploadedFiles/" + Path.GetFileName(photo.FileName);
                 db.Entry(changeProfile).State = EntityState.Modified;
                 db.SaveChanges();
                 ViewBag.Message = "File uploaded successfully";
             }
             catch (Exception ex)
             {
                 ViewBag.Message = "ERROR:" + ex.Message.ToString();
             }
         }
         else
         {
             ViewBag.Message = "You have not specified a file.";
         }
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View("Index"));
 }
Example #4
0
        private void Button_Click_Configuration(object sender, RoutedEventArgs e)
        {
            ChangeProfile d = new ChangeProfile();

            d.Show();
            this.Close();
        }
Example #5
0
 void Start()
 {
     Anim      = GetComponent <Animator>();
     Want      = GetComponent <Wanted>();
     CG        = TargetImage.GetComponent <ChangeProfile>();
     GM        = GameObject.Find("GameManager").GetComponent <GameManager>();
     AudioSour = GameObject.Find("GameManager").GetComponent <AudioSource>();
 }
Example #6
0
        public ActionResult ChangeProfile()
        {
            MyIdentityUser user  = userManager.FindByName(HttpContext.User.Identity.Name);
            ChangeProfile  model = new ChangeProfile();

            model.FullName  = user.FullName;
            model.BirthDate = user.BirthDate;
            model.Bio       = user.Bio;
            return(View(model));
        }
        public ActionResult ChangeProfile()
        {
            DTIdentityUser user  = userManager.FindByName(HttpContext.User.Identity.Name);
            ChangeProfile  model = new ChangeProfile();

            model.FirstName = user.FirstName;
            model.LastName  = user.LastName;
            model.Email     = user.Email;
            return(View(model));
        }
Example #8
0
        public async Task <IActionResult> PutUser([FromRoute] int id, [FromBody] ChangeProfile user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.Id)
            {
                return(BadRequest());
            }

            if (User.Claims.Single(x => x.Type == ClaimTypes.Role).Value == "User")
            {
                if (Convert.ToInt32(User.FindFirstValue("Sub")) != id || Convert.ToInt32(User.FindFirstValue("Sub")) != user.Id)
                {
                    return(BadRequest("id пользователя не соответствует запрашиваемому id."));
                }
            }

            //_context.Entry(user).State = EntityState.Modified;

            User current_user = _context.Users.Find(id);

            _context.Entry(current_user).Property(x => x.Name).CurrentValue    = user.Name;
            _context.Entry(current_user).Property(x => x.Surname).CurrentValue = user.Surname;
            if (user.Pass.ToLower() != "empty")
            {
                _context.Entry(current_user).Property(x => x.Pass).CurrentValue = user.Pass;
                _context.Entry(current_user).Property(x => x.Name).IsModified   = true;
            }

            _context.Entry(current_user).Property(x => x.Surname).IsModified = true;
            _context.Entry(current_user).Property(x => x.Pass).IsModified    = true;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public ChangeProfileAction(ChangeProfile value)
 {
     InitializeComponent();
     label1.Text = Texts.rm.GetString("PERFILINFOLABEL", Texts.cultereinfo);
     if (value != null)
     {
         window = value;
         if (value.profile != null)
         {
             ProfileStaticHelper.SelectItemByValue(comboBox1, ProfileStaticHelper.SelectPerfilByName(value.profile));
             //  comboBox1.SelectedItem = value.profile;
         }
     }
     loadProfiles();
 }
Example #10
0
        public IActionResult ChangeProfile(int id = 0)
        {
            currentProfile = id == 0 ? db.Users.FirstOrDefault(u => u.Nickname == User.Identity.Name) : db.Users.FirstOrDefault(u => u.Id == id);
            CountScore();
            ChangeProfile model = new ChangeProfile
            {
                Name     = currentProfile.Name,
                Nickname = currentProfile.Nickname,
                Email    = currentProfile.Email,
                Cash     = currentProfile.Cash
            };

            model.SoldLots      = db.Lots.Where(l => l.HostId == currentProfile.Id && l.Status != "sell").ToArray();
            model.PurchasedLots = db.Lots.Where(l => l.HostId == currentProfile.Id && l.Status == "sell").ToArray();

            return(View(model));
        }
Example #11
0
        public ActionResult ChangeProfile()
        {
            ChangeProfile     user1   = new ChangeProfile();
            List <AspNetUser> lstUser = db.AspNetUsers.ToList();

            foreach (var user in lstUser)
            {
                if (user.Id.Equals(User.Identity.GetUserId()))
                {
                    user1.PhoneNumber = user.PhoneNumber;
                    user1.Address     = user.Address;
                    user1.Name        = user.Name;
                    db.SaveChanges();
                    return(View(user1));
                }
            }
            return(View());
        }
Example #12
0
 public ActionResult ChangeProfile(ChangeProfile model)
 {
     if (ModelState.IsValid)
     {
         MyIdentityUser user = userManager.FindByName(HttpContext.User.Identity.Name);
         user.FullName  = model.FullName;
         user.BirthDate = model.BirthDate;
         user.Bio       = model.Bio;
         IdentityResult result = userManager.Update(user);
         if (result.Succeeded)
         {
             ViewBag.Message = "Profile updated successfully.";
         }
         else
         {
             ModelState.AddModelError("", "Error while saving profile.");
         }
     }
     return(View(model));
 }
Example #13
0
        public ActionResult ChangeProfile(ChangeProfile model)
        {
            List <AspNetUser> lstUser = db.AspNetUsers.ToList();

            foreach (var user in lstUser)
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                if (user.Id.Equals(User.Identity.GetUserId()))
                {
                    user.PhoneNumber = model.PhoneNumber;
                    user.Address     = model.Address;
                    user.Name        = model.Name;
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View());
        }
        public ActionResult ChangeProfile(ChangeProfile model)
        {
            if (ModelState.IsValid)
            {
                DTIdentityUser user = userManager.FindByName(HttpContext.User.Identity.Name);
                user.FirstName = model.FirstName;
                user.LastName  = model.LastName;
                user.Email     = model.Email;
                IdentityResult result = userManager.Update(user);

                if (result.Succeeded)
                {
                    ViewBag.Message = "Profile updated successfully.";
                    //TODO: put a redirect here to the user page.
                }
                else
                {
                    ModelState.AddModelError("", "Error while saving profile.");
                }
            }
            return(View(model));
        }
        public void ChangeProfileShouldCreateTheProfile()
        {
            //ARRANGE
            var id    = Guid.NewGuid();
            var model = new ChangeProfile {
                Day = 13, Month = 09, Year = 1984, SecretQuestionId = id, Answer = "test"
            };
            const string userName = "******";
            var          user     = new User {
                Id = "9fa22176-d0d4-4746-bc3d-28dd01ffae29"
            };

            var userMock = new Mock <IPrincipal>();

            userMock
            .Setup(p => p.Identity.Name)
            .Returns(userName);

            var context = new Mock <HttpContextBase>();

            context
            .Setup(ctx => ctx.User)
            .Returns(userMock.Object);

            var controllerContext = new Mock <ControllerContext>();

            controllerContext
            .Setup(con => con.HttpContext)
            .Returns(context.Object);

            var userLogic = new Mock <IUserLogic>();

            userLogic
            .Setup(x => x.FindByName(userName))
            .Returns(user)
            .Verifiable("Should get the user.");

            userLogic
            .Setup(x => x.Update(user))
            .Returns(true)
            .Verifiable("Should create the user");

            var secretQuestionLogic = new Mock <ISecretQuestionLogic>();

            secretQuestionLogic
            .Setup(x => x.SaveSecretQuestionForUser(user.Id, id))
            .Verifiable("Should save secret question choice.");

            var encryptionHelper = new Mock <IEncryptionHelper>();

            encryptionHelper
            .Setup(x => x.EncryptString("test", "JellyTank"))
            .Verifiable();

            var controller = new ProfileController(userLogic.Object, secretQuestionLogic.Object, encryptionHelper.Object)
            {
                ControllerContext = controllerContext.Object
            };

            //ACT
            var result = controller.ChangeProfile(model) as RedirectToRouteResult;

            //ASSERT
            userLogic.Verify();
            secretQuestionLogic.Verify();
            encryptionHelper.Verify();

            Assert.NotNull(result);
            Assert.AreEqual("Index", result.RouteValues["Action"]);
            Assert.AreEqual("Home", result.RouteValues["Controller"]);
        }
Example #16
0
        public ActionResult Index(ChangeProfile model, HttpPostedFileBase photo, string Fluents, string Natives, string Interests)
        {
            ViewBag.LanguageID = new SelectList(db.LanguagesTable, "Language", "Language"); //(Diego)
            var userId      = User.Identity.GetUserId <int>();
            var user        = db.AspNetUsers.Find(userId);
            var userProfile = db.UserProfile.Find(userId);

            userProfile.Name        = model.Name;
            user.Email              = model.Email;
            user.PhoneNumber        = model.PhoneNumber;
            userProfile.Nationality = model.Nationality;
            userProfile.Age         = model.Age;

            if (photo != null && photo.ContentLength > 0)
            {
                try
                {
                    string path = Path.Combine(Server.MapPath("~/UploadedFiles/"), Path.GetFileName(photo.FileName));
                    photo.SaveAs(path);
                    userProfile.Photo           = "/UploadedFiles/" + Path.GetFileName(photo.FileName);
                    db.Entry(userProfile).State = EntityState.Modified;
                    db.SaveChanges();
                    ViewBag.Message = "File uploaded successfully";
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            }
            else
            {
                ViewBag.Message = "You have not specified a file.";
            }


            ObjectParameter l = new ObjectParameter("LanguageID", typeof(int));



            userProfile.LanguagesTable.Clear();
            if (Fluents != "")
            {
                string[] fluents = Fluents.Split(',');
                foreach (var langStr in fluents)
                {
                    db.sp_getLanguageID(langStr, l);
                    userProfile.LanguagesTable.Add(db.LanguagesTable.Find(l.Value));
                }
            }

            userProfile.LanguagesTable1.Clear();
            if (Interests != "")
            {
                string[] interests = Interests.Split(',');
                foreach (var langStr in interests)
                {
                    db.sp_getLanguageID(langStr, l);
                    userProfile.LanguagesTable1.Add(db.LanguagesTable.Find(l.Value));
                }
            }

            userProfile.LanguagesTable2.Clear();
            if (Natives != "")
            {
                string[] natives = Natives.Split(',');
                foreach (var langStr in natives)
                {
                    db.sp_getLanguageID(langStr, l);
                    userProfile.LanguagesTable2.Add(db.LanguagesTable.Find(l.Value));
                }
            }

            db.SaveChanges();
            return(RedirectToAction("EventsList", "EventTables"));
        }
Example #17
0
        // GET: /Manage/Index
        public ActionResult Index(ManageMessageId?message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";


            //var model = new IndexViewModel
            //{
            //    HasPassword = HasPassword(),
            //    PhoneNumber = await UserManager.GetPhoneNumberAsync(userId),
            //    TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId),
            //    Logins = await UserManager.GetLoginsAsync(userId),
            //    BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(User.Identity.GetUserId())
            //};

            var model = new ChangeProfile();

            var userId      = User.Identity.GetUserId <int>();
            var user        = db.AspNetUsers.Find(userId);
            var userProfile = db.UserProfile.Find(userId);

            model.Email              = user.Email;
            model.PhoneNumber        = user.PhoneNumber;
            model.Nationality        = userProfile.Nationality;
            model.Name               = userProfile.Name;
            model.Age                = userProfile.Age;
            model.Photo              = userProfile.Photo;
            model.FluentLanguage     = userProfile.LanguagesTable;
            model.InterestedLanguage = userProfile.LanguagesTable1;
            model.NativeLanguage     = userProfile.LanguagesTable2;

            ViewBag.LanguageID    = new SelectList(db.LanguagesTable, "Language", "Language", userProfile.Nationality);         //(Diego)
            ViewBag.NationalityID = new SelectList(db.NationalityTable, "Nationality", "Nationality", userProfile.Nationality); //(Diego)

            string json = "[";

            //List<string> availableLanguages = new List<string>();
            foreach (var item in db.LanguagesTable)
            {
                json = json + "," + item.Language;
            }
            json = json + "]";
            model.ListLanguages = json;

            ViewBag.NationalityID = new SelectList(db.NationalityTable, "Nationality", "Nationality", userProfile.Nationality); //(Diego)

            //string json2 = "[";
            //List<string> availableNationalities = new List<string>();
            //foreach (var item in db.NationalityTable)
            //{
            //    json2 = json2 + "," + item.Nationality;
            //}
            //json2 = json2 + "]";
            //model.ListNationalities = json2;


            return(View(model));
        }