예제 #1
0
        public void updateUser(int idUser, Users newUser)
        {
            Users user = db.users.FirstOrDefault(m => m.id == idUser);

            user = newUser;
            db.SaveChanges();
        }
 public void sendEmailToAuthenticateAUserTest()
 {
     EmailController target = new EmailController(); // TODO: Initialize to an appropriate value
     Users user = new Users();
     user.name = "greganati";
     target.sendEmailToAuthenticateAUser(user);
     Assert.IsNotNull(user);
 }
 public void connectNoExistingUserTest()
 {
     Users users = null;
     iUserServices.Setup(m => m.findUserByUserName(It.IsAny<string>())).Returns(users);
     UserController target = new UserController(iCommentServices.Object,iUserServices.Object);
     Users user = new Users();
     var actual = target.connect(user) as RedirectToRouteResult;
     Assert.IsNotNull(actual);
     Assert.AreEqual(actual.RouteValues["action"], "indexWithoutVoice");
     Assert.AreEqual(actual.RouteValues["controller"], "Home");
 }
 public void connectExistingUserAndDiferentePasswordTest()
 {
     CryptographyController cryptoController = new CryptographyController();
     Users user1 = new Users();
     Users user2 = new Users();
     user1.password = cryptoController.getMD5Hash("teste");
     iUserServices.Setup(m => m.findUserByUserName(It.IsAny<string>())).Returns(user1);
     UserController target = new UserController(iCommentServices.Object, iUserServices.Object);
     UserController target2 = new UserController(iCommentServices.Object, iUserServices.Object);
     user2.password = "******";
     var actual = target.connect(user2) as RedirectToRouteResult;
     Assert.IsNotNull(actual);
     Assert.AreEqual(actual.RouteValues["action"], "indexWithoutVoice");
     Assert.AreEqual(actual.RouteValues["controller"], "Home");
 }
        public void addNewUserForApp(string idFacebook, string accessToken, string name, string email, string phoneId, string visionProblem)
        {
            Models.Users user;
            Users newUser = new Users();
            user = userServices.findUserByPhoneId(phoneId);
            if (user != null)
            {
                newUser.acessTokenFacebook = accessToken;
                newUser.idFacebook = idFacebook;
                newUser.name = name;
                newUser.userName = email;
                userServices.updateUser(user.id, newUser);
                return;
            }

            user = new Users();
            string password = cryptographyController.randomString(6);
            user.acessTokenFacebook = accessToken;
            user.idFacebook = idFacebook;
            user.userName = email;
            user.name = name;

            switch (visionProblem)
            {
                case("totallyBlind"):
                    user.typeOfBlindness = 1;
                    break;

                case ("lowVision"):
                    user.typeOfBlindness = 2;
                    break;

                case ("partiallySighted"):
                    user.typeOfBlindness = 3;
                    break;

            }

            user.password = cryptographyController.getMD5Hash(password);
            user.hash = cryptographyController.getMD5Hash(user.name + user.password + DateTime.Now.ToString());
            user.phoneId = phoneId;
            userServices.addUser(user);

            emailController.sendPasswordToUser(user.userName, password);
        }
        public void sendEmailToAuthenticateAUser(Users user)
        {
            try
            {
                System.Collections.Generic.List<string> listColl = new System.Collections.Generic.List<string>();
                ////TODO - Write a simple loop to add the recipents email addresses to the listColl object.
                listColl.Add(user.userName.ToString());

                Amazon.SimpleEmail.AmazonSimpleEmailServiceClient client = new Amazon.SimpleEmail.AmazonSimpleEmailServiceClient("AKIAJUPAMCIGTBC2ODXQ", "s7PkEfwVmhbzWT5PFeN5CV3ZzSPemgaaxnwa32pp");
                SendEmailRequest mailObj = new SendEmailRequest();

                Destination destinationObj = new Destination(listColl);

                mailObj.Source = "*****@*****.**";
                ////The from email address
                mailObj.ReturnPath = "*****@*****.**";
                ////The email address for bounces
                mailObj.Destination = destinationObj;

                string urlLink = "http://ec2-177-71-137-221.sa-east-1.compute.amazonaws.com/smartaudiocityguide/User/authenticateUser/?hash=" + user.hash;
                ////Create Message
                Amazon.SimpleEmail.Model.Content emailSubjectObj = new Amazon.SimpleEmail.Model.Content("Authentication for Smart Audio City Guide");
                Amazon.SimpleEmail.Model.Content emailBodyContentObj = new Amazon.SimpleEmail.Model.Content(@"<htm>
                <head>
                <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
                <title>Smart Audio City Guide</title>
                </head>
                <body>
                <div>
                    <a> Welcome " + user.name + "to Smart Audio City Guide </a><br/><a>Click on the link to authenticate your account: <a href='"+urlLink+"'>"+ urlLink+ "</a></a></div></body>");

                Amazon.SimpleEmail.Model.Body emailBodyObj = new Amazon.SimpleEmail.Model.Body();
                emailBodyObj.Html = emailBodyContentObj;
                Message emailMessageObj = new Message(emailSubjectObj, emailBodyObj);
                mailObj.Message = emailMessageObj;

                dynamic response2 = client.SendEmail(mailObj);
            }
            catch (Exception)
            {

            }
        }
        public ActionResult connect(Users user)
        {
            Users userToEnter = new Users();
            userToEnter = userServices.findUserByUserName(user.userName);

            if (userToEnter == null)
            {
                ModelState.AddModelError("user", "User not found.");
                TempData["ModelState"] = ModelState;
                return RedirectToAction("indexWithoutVoice", "Home");
            }

            if (userToEnter.password != cryptographyController.getMD5Hash(user.password))
            {
                ModelState.AddModelError("password", "Wrong password.");
                TempData["ModelState"] = ModelState;
                return RedirectToAction("indexWithoutVoice", "Home");
            }

            if(userToEnter.authenticate == 0)
            {
                //ModelState.AddModelError("authentication", "Authentication has been sent again to your e-mail.");
                // emailController.sendEmailToAuthenticateAUser(userToEnter);
                //TempData["ModelState"] = ModelState;
                return RedirectToAction("indexWithoutVoice", "Home");
            }

            try
            {
                userSession.currentUser = userToEnter;
            }
            catch
            {

            }
            return RedirectToAction("index","User");
        }
 public void registerOkTest()
 {
     iUserServices.Setup(m => m.hasAUserWithThisEmail(It.IsAny<string>())).Returns(false);
     iUserServices.Setup(m => m.addUser(It.IsAny<Users>()));
     UserController target = new UserController(iCommentServices.Object, iUserServices.Object);
     Users user = new Users();
     Random random = new Random();
     user.password = random.Next().ToString();
     RedirectToRouteResult actual = target.register(user, user.password) as RedirectToRouteResult;
     Assert.IsNotNull(actual);
     Assert.AreEqual(actual.RouteValues["action"], "index");
     Assert.AreEqual(actual.RouteValues["controller"], "Home");
 }
 public void registerDiferrentPasswordTest()
 {
     UserController target = new UserController(iCommentServices.Object, iUserServices.Object);
     Users user = new Users();
     string confirmPassword = "******";
     user.password = "******";
     ViewResult actual = target.register(user,confirmPassword) as ViewResult;
     TempDataDictionary tempData = actual.TempData as TempDataDictionary;
     ModelStateDictionary modelState = tempData["ModelState"] as ModelStateDictionary;
     Assert.IsNotNull(actual);
     Assert.IsTrue(modelState.ContainsKey("password"));
     Assert.IsTrue(modelState.ContainsKey("confirmPassword"));
 }
 public void registerAlreadyExistUserTest()
 {
     iUserServices.Setup(m => m.hasAUserWithThisEmail(It.IsAny<string>())).Returns(true);
     UserController target = new UserController(iCommentServices.Object, iUserServices.Object);
     Users user = new Users();
     Random random = new Random();
     user.password =  random.Next().ToString();
     ViewResult actual = target.register(user, user.password) as ViewResult;
     TempDataDictionary tempData = actual.TempData as TempDataDictionary;
     ModelStateDictionary modelState = tempData["ModelState"] as ModelStateDictionary;
     Assert.IsNotNull(actual);
     Assert.IsTrue(modelState.ContainsKey("userName"));
 }
예제 #11
0
 public void addUser(Users user)
 {
     db.users.Add(user);
     db.SaveChanges();
 }
        public ActionResult register(Users user, string confirmPassword)
        {
            if (!ModelState.IsValid)
                return View("register");

            if (confirmPassword != user.password)
            {
                ModelState.AddModelError("password", "Password are not the same.");
                ModelState.AddModelError("confirmPassword", " ");
                TempData["ModelState"] = ModelState;
                return View("register");
            }

            bool alreadyHasThisUser = userServices.hasAUserWithThisEmail(user.userName);

            if (alreadyHasThisUser == true)
            {
                ModelState.AddModelError("userName", "Already has this user.");
                TempData["ModelState"] = ModelState;
                return View("register");
            }

            user.password = cryptographyController.getMD5Hash(user.password);
            user.hash = cryptographyController.getMD5Hash(user.userName + user.password + DateTime.Now.ToString());
            user.authenticate = 1;
            userServices.addUser(user);

            //emailController.sendEmailToAuthenticateAUser(user);

            return RedirectToAction("index", "Home");
        }