예제 #1
0
        public UserMongoMap GetMongoMap(User userData)
        {
            if (userData == null)
                throw new ArgumentNullException("userData");

            if (string.IsNullOrEmpty(userData.Id))
            {
                this.IsNew = true;
                this.Id = ObjectId.GenerateNewId();
            }
            else
                this.Id = new ObjectId(userData.Id);

            this.Name = userData.Name;
            this.Email = userData.Email;

            if (userData.ServicesList != null)
            {
                this.ServicesList = new List<ServiceMongoMap>();
                foreach (var item in userData.ServicesList)
                {
                    var service = new ServiceMongoMap().GetMongoMap(item);
                    if(service == null)
                        continue;

                    this.ServicesList.Add(service);
                }
            }

            this.Status = userData.Status.GetUserStatusEnumStringValue();
            this.CreationTime = userData.CreateTime;

            return this;
        }
예제 #2
0
        public ActionResult SaveUser(UserModel model) {
            try {
                User user = new User();
                user.id = model.id;
                user.CustomerId = SessionData.customer.id;
                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.WorkPhone = model.WorkPhone.FormatPhone();
                user.MobilePhone = model.MobilePhone.FormatPhone();
                user.Password = model.Password;
                user.Hash = model.LastName.ToHashMD5();
                user.Active = (model.Active == Common.Status.Active);
                user.Type = (Int32)model.Type;
                user.Email = model.Email;
                user.ImageUrl = model.ImageUrl;
                if (model.Image != null) {
                    if (user.id == 0)
                        user.ImageUrl = Path.GetExtension(model.Image.FileName);
                    else
                        user.ImageUrl = String.Format("{0}{1}", model.id, Path.GetExtension(model.Image.FileName));
                }
                if (user.id == 0) {
                    EmailHelper.SendEmailConfirmation(this.ControllerContext, user);
                }

                Int32 result = _userService.SaveUser(user);
                if (result == 0)
                    return RedirectToAction("Index", "Error");

                String fileName = (model.Image == null ? model.ImageUrl : model.Image.FileName);
                String path = Path.Combine(Server.MapPath("~/Images/Menus/"), SessionData.customer.id.ToString(), "users", String.Format("{0}{1}", result, Path.GetExtension(fileName)));
                if (model.Image == null && model.ImageUrl == null) {
                    if (System.IO.File.Exists(path)) {
                        System.IO.File.Delete(path);
                    }
                }
                else if (model.Image != null) {
                    model.Image.SaveAs(path);
                }

                if (model.Referer == "Form") {
                    return RedirectToAction("Index", "Login");
                }
                else {
                    return RedirectToAction("Index", "Users", new { id = user.CustomerId });
                }
            }
            catch (Exception ex) {
                base.Log(ex);
            }
            finally {
            }

            return null;
        }
        public ActionResult Index(RegistrationModel model) {
            // Save Customer info
            Customer customer;
            User user;

            try {
                customer = new Customer();
                user = new User();

                customer.id = 0;
                customer.Name = model.Customer.Name;
                customer.Address = model.Customer.Address;
                customer.Address2 = model.Customer.Address2;
                customer.City = model.Customer.City;
                customer.State = model.Customer.State;
                customer.Zip = model.Customer.Zip;
                customer.Phone = model.Customer.Phone;
                customer.Tax = model.Customer.Tax;
                customer.ImageUrl = model.Customer.ImageUrl;

                Int32 result = _customerService.SaveCustomer(customer);
                // Save registered modules
                _customerService.SaveModulesByCustomer(result, model.Modules.Split(',').Select(Int32.Parse).ToArray());

                SessionData.customer = customer;

                // Save user personal info
                user.id = 0;
                user.CustomerId = SessionData.customer.id;
                user.FirstName = model.User.FirstName;
                user.LastName = model.User.LastName;
                user.WorkPhone = model.User.WorkPhone.CleanPhone();
                user.MobilePhone = model.User.MobilePhone.CleanPhone();
                user.Password = model.User.Password;
                user.Email = model.User.Email;
                user.Active = false;
                user.Hash = Utility.GetNewConfirmationNumber();
                user.Type = (Int32)Common.UserType.Administrator;

                result = _userService.SaveUser(user);
                SessionData.user = user;
                base.Log(Common.LogType.Activity, "Registering", String.Format("{0} {1}, phone#{2}, mobile#{3}", model.User.FirstName, model.User.LastName, model.User.WorkPhone, model.User.MobilePhone));

                EmailHelper.SendEmailConfirmation(this.ControllerContext, user);
                return RedirectToAction("Index", "Login");
            }
            catch (Exception ex) {
                base.Log(ex);
            }
            finally {
            }

            return null;
        }
 public ActionResult EmailConfirmation(String hash) {
     User model;
     try {
         model = new Services.User();
         model = _userService.GetUserByHash(hash);
         return View("EmailConfirmation", model);
     }
     catch (Exception ex) {
         base.Log(ex);
     }
     return null;
 }
예제 #5
0
        public static Boolean SendEmailConfirmation(ControllerContext context, User user) {
            String emailBody = String.Empty;
            ViewDataDictionary viewData = new ViewDataDictionary(user);

            using (StringWriter sw = new StringWriter()) {
                ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(context, "Emails/_EmailConfirmationPartial");
                ViewContext viewContext = new ViewContext(context, viewResult.View, viewData, new TempDataDictionary(), sw);
                viewResult.View.Render(viewContext, sw);
                emailBody = sw.GetStringBuilder().ToString();
            }
            return SendEmail(user.Email, "MenuzRus email confirmation", emailBody);
        }
예제 #6
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            MvcHandler handler;
            String     route   = null;
            String     culture = null;

            base.OnActionExecuting(filterContext);

            Services.User user = SessionData.GetSession <Services.User>(Constants.SESSION_USER);

            this.IsLoggedIn   = (SessionData.user != null);
            SessionData.route = this.BuildRoute();

            try {
                // Get the route
                handler = this.HttpContext.Handler as MvcHandler;
                if (handler != null && handler.RequestContext != null && handler.RequestContext.RouteData != null)
                {
                    // Route
                    if (handler.RequestContext.RouteData.Values != null && handler.RequestContext.RouteData.Route != null)
                    {
                        route = handler.RequestContext.RouteData.Route.GetVirtualPath(handler.RequestContext, handler.RequestContext.RouteData.Values).VirtualPath;
                    }
                }

                if (user != null)
                {
                    this.LogAcvitity(filterContext);
                }

                if (Request.Cookies["language"] != null)
                {
                    culture = Server.HtmlEncode(Request.Cookies["language"].Value);
                }

                if (SessionData.customer != null)
                {
                    if (SessionData.GetSession <String>(Constants.SESSION_LANGUAGE) != null)
                    {
                        culture = EnumHelper <CommonUnit.Languages> .GetDisplayValue((CommonUnit.Languages) Convert.ToInt32(SessionData.GetSession <String>(Constants.SESSION_LANGUAGE)));
                    }
                }
                if (!String.IsNullOrEmpty(culture))
                {
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
                }
            }
            catch (Exception ex) {
                throw ex;
            }
        }
예제 #7
0
        public ActionResult EmailConfirmation(String hash)
        {
            User model;

            try {
                model = new Services.User();
                model = _userService.GetUserByHash(hash);
                return(View("EmailConfirmation", model));
            }
            catch (Exception ex) {
                base.Log(ex);
            }
            return(null);
        }
 public User Confirm(String hash) {
     try {
         menuzRusDataContext db = new menuzRusDataContext(base.connectionString);
         user = db.Users.Where(m => m.Hash == hash).FirstOrDefault();
         if (user != default(User)) {
             user.Active = true;
             user.EmailConfirmed = true;
             db.SubmitChanges();
         }
     }
     catch (Exception ex) {
         return null;
     }
     return user;
 }
예제 #9
0
 public Boolean DeleteUser(Int32? id) {
     User query = new User();
     id = id.HasValue ? id : 0;
     try {
         using (menuzRusDataContext db = new menuzRusDataContext(base.connectionString)) {
             query = db.Users.Where(m => m.id == id).FirstOrDefault();
             if (query != default(User)) {
                 db.Users.DeleteOnSubmit(query);
             }
             db.SubmitChanges();
         }
     }
     catch (Exception ex) {
         return false;
     }
     return true;
 }
예제 #10
0
        public void Authenticate_Adds_New_Device()
        {
            // Arrange
            const string userPass = "******";
            const string hardwareId = "H123";
            var testUser = new User { Email = "*****@*****.**" };
            var userList = new List<User> { testUser }.AsQueryable();
            var userRepository = new Mock<IUserRepository>();
            userRepository.Setup(u => u.FindAll()).Returns(userList);

               var userService = ServiceMiniMart.CreateUserService(userRepository);
            userService.GenerateUserPassword(testUser, userPass);

            // Act
            var result = userService.Authenticate(testUser.Email, userPass, hardwareId);

            // Assert
            Assert.AreEqual(1, testUser.Devices.Count);
        }
예제 #11
0
        public void Authenticate_Facebook_Returns_False_For_Invalid_User()
        {
            // Arrange
            var profile = new UserProfile
            {
                FacebookId = 123
            };
            var testUser = new User { FacebookId = 456, Email = "*****@*****.**" };
            var userList = new List<User> { testUser }.AsQueryable();
            var userRepository = new Mock<IUserRepository>();
            userRepository.Setup(u => u.FindAll()).Returns(userList);

               var userService = ServiceMiniMart.CreateUserService(userRepository);

            // Act
            var result = userService.AuthenticateFacebookUser(profile);

            // Assert
            Assert.IsFalse(result);
        }
예제 #12
0
        public User GetUserModel()
        {
            var status = this.Status.GetUserStatusEnum();

            IList<Service> servicesList = null;
            if (this.ServicesList != null && this.ServicesList.Any())
            {
                servicesList = new List<Service>();
                foreach (var item in this.ServicesList)
                {
                    var service = item.GetServiceModel();
                    if(service == null)
                        continue;

                    servicesList.Add(service);
                }
            }

            var result = new User()
                .SetDataFromDatabase(this.Id.ToString(), this.Name, this.Email, servicesList, status, this.CreationTime);

            return result;
        }
예제 #13
0
        public void Authenticate_Facebook_Links_Existing_User_To_Profile()
        {
            // Arrange
            var profile = new UserProfile
            {
                FacebookId = 123,
                Email = "*****@*****.**",
                AccessToken = "validaccess"
            };
            var testUser = new User { Email = "*****@*****.**" };
            var userList = new List<User> { testUser }.AsQueryable();
            var userRepository = new Mock<IUserRepository>();
            userRepository.Setup(u => u.FindAll()).Returns(userList);

               var userService = ServiceMiniMart.CreateUserService(userRepository);

            // Act
            var result = userService.AuthenticateFacebookUser(profile);

            // Assert
            Assert.AreEqual(profile.AccessToken, testUser.AccessToken);
            Assert.IsTrue(result);
        }
예제 #14
0
        public Int32 SaveUser(User user) {
            User query = new User();
            try {
                using (menuzRusDataContext db = new menuzRusDataContext(base.connectionString)) {
                    if (user.id != 0)
                        query = db.Users.Where(m => m.id == user.id).FirstOrDefault();

                    if (query != default(User)) {
                        query.CustomerId = user.CustomerId;
                        query.Active = user.Active;
                        query.FirstName = user.FirstName;
                        query.LastName = user.LastName;
                        query.MobilePhone = user.MobilePhone;
                        query.WorkPhone = user.WorkPhone;
                        query.Email = user.Email;
                        query.Password = user.Password;
                        query.ImageUrl = user.ImageUrl;
                        query.Type = user.Type;
                        query.Hash = user.Hash;
                    }
                    if (user.id == 0) {
                        db.Users.InsertOnSubmit(query);
                    }
                    db.SubmitChanges();
                    // Update ImageName for new user
                    if (user.id == 0 && query.ImageUrl != null) {
                        query.ImageUrl = String.Format("{0}{1}", query.id, user.ImageUrl);
                        db.SubmitChanges();
                    }
                }
            }
            catch (Exception ex) {
                return 0;
            }
            return query.id;
        }
예제 #15
0
 partial void InsertUser(User instance);
예제 #16
0
        public void UpdateUser_Keeps_Old_Password()
        {
            // Arrange

            var userRepository = new Mock<IUserRepository>();

               var userService = ServiceMiniMart.CreateUserService(userRepository);
            var oldPass = Encoding.ASCII.GetBytes("oldpass");
            var updateUser = new User { Email = "*****@*****.**", HashedPassword = oldPass };

            // Act
            userService.UpdateUser(updateUser);

            // Assert
            Assert.AreEqual(oldPass, updateUser.HashedPassword);
        }
예제 #17
0
        public void UpdateUser_Hashes_New_Password()
        {
            // Arrange
            var updateUser = new User { Email = "*****@*****.**" };
            var newPass = "******";

            var userRepository = new Mock<IUserRepository>();

               var userService = ServiceMiniMart.CreateUserService(userRepository);

            // Act
            userService.UpdateUser(updateUser, newPass);

            // Assert
            Assert.NotNull(updateUser.HashedPassword);
        }
예제 #18
0
 partial void DeleteUser(User instance);
예제 #19
0
        public void GetUsers_Returns_List_Of_Users()
        {
            // Arrange
            var foundUser = new User { Email = "*****@*****.**" };
            var userList = new List<User> { foundUser, foundUser }.AsQueryable();
            const int currentPage = 1;
            const int numPerPage = 10;
            int total = 0;
            var filter = new UserFilter();
            var userRepository = new Mock<IUserRepository>();
            userRepository.Setup(u => u.Search(filter, currentPage, numPerPage, ref total)).Returns(userList);

            var userService = ServiceMiniMart.CreateUserService(userRepository);

            // Act
            var returnedList = userService.GetUsers(filter, currentPage, numPerPage);

            // Assert
            Assert.AreEqual(userList.Count(), returnedList.Items.Count);
        }
 public virtual bool Login(User _model,ref string username, ref int userid, ref int group,  ref int examineeid)
 {
     return Service.Login(_model,ref username,ref  userid, ref  group, ref examineeid);
 }
예제 #21
0
        public void Authenticate_True_With_Valid_Auth_Token()
        {
            const string authToken = "GoodToken";
            var testUser = new User { AuthToken = "GoodToken" };
            var userRepository = new Mock<IUserRepository>();
            var userList = new List<User> { testUser }.AsQueryable();
            userRepository.Setup(u => u.FindAll()).Returns(userList);

            var userService = ServiceMiniMart.CreateUserService(userRepository);

            // Act
            var result = userService.Authenticate(authToken);

            // Assert
            Assert.AreEqual(testUser,result);
        }
예제 #22
0
		private void detach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.Customer = null;
		}
예제 #23
0
        public void Generate_Forgot_Password_Sends_Mail_For_Valid_User()
        {
            // Arrange
            var profile = new UserProfile
            {
                FacebookId = 123,
                Email = "*****@*****.**"
            };
            var testUser = new User { FacebookId = 456, Email = profile.Email };
            var userList = new List<User> { testUser }.AsQueryable();
            var userRepository = new Mock<IUserRepository>();
            userRepository.Setup(u => u.FindAll()).Returns(userList);

               var userService = ServiceMiniMart.CreateUserService(userRepository);

            // Act
            var result = userService.GenerateForgotPasswordLink("", profile.Email);

            // Assert
            Assert.IsTrue(result);
        }
예제 #24
0
        public void Authenticate_True_With_Valid_Credentials()
        {
            // Arrange
            const string userPass = "******";
            var testUser = new User { Email = "*****@*****.**" };
            var userList = new List<User> { testUser }.AsQueryable();
            var userRepository = new Mock<IUserRepository>();
            userRepository.Setup(u => u.FindAll()).Returns(userList);

               var userService = ServiceMiniMart.CreateUserService(userRepository);
            userService.GenerateUserPassword(testUser, userPass);

            // Act
            var result = userService.Authenticate(testUser.Email, userPass);

            // Assert
            Assert.AreEqual(testUser, result);
        }
예제 #25
0
        public void CreateUser_Saves_To_Repository_With_Phone()
        {
            // Arrange
            var newUser = new User { Email = "*****@*****.**", CellPhone = "(410) 555-5555" };

            var userRepository = new Mock<IUserRepository>();

               var userService = ServiceMiniMart.CreateUserService(userRepository);

            // Act
            userService.CreateUser(newUser);

            // Assert
            userRepository.Verify(u => u.Save(newUser));
            Assert.Pass();
        }
예제 #26
0
        public void Authenticate_Updates_Existing_Device_Token()
        {
            // Arrange
            const string userPass = "******";
            const string hardwareId = "H123";
            const string oldToken = "oldtoken";
            var testUser = new User { Email = "*****@*****.**" };
            testUser.Devices.Add(new Device {HardwareId = hardwareId, AuthToken = oldToken});
            var userList = new List<User> { testUser }.AsQueryable();
            var userRepository = new Mock<IUserRepository>();
            userRepository.Setup(u => u.FindAll()).Returns(userList);

               var userService = ServiceMiniMart.CreateUserService(userRepository);
            userService.GenerateUserPassword(testUser, userPass);

            // Act
            var result = userService.Authenticate(testUser.Email, userPass, hardwareId);

            // Assert
            Assert.AreEqual(1, testUser.Devices.Count);
            Assert.AreNotEqual(oldToken, testUser.Devices.FirstOrDefault().AuthToken);
        }
예제 #27
0
		private void attach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.Customer = this;
		}
예제 #28
0
        public void GetUserByFacebookId_Returns_Matching_User()
        {
            // Arrange
            const long facebookId = 123;
            var foundUser = new User { FacebookId = facebookId, Email = "*****@*****.**" };
            var userList = new List<User> { foundUser }.AsQueryable();

            var userRepository = new Mock<IUserRepository>();
            userRepository.Setup(u => u.FindAll()).Returns(userList);

               var userService = ServiceMiniMart.CreateUserService(userRepository);

            // Act
            var user = userService.GetUserByFacebookId(facebookId);

            // Assert
            Assert.AreEqual(foundUser, user);
        }
예제 #29
0
        public void GetUserByFacebookResetToken_Returns_Matching_User()
        {
            // Arrange
            const string resetToken = "testtoken";
            var foundUser = new User { Email = "*****@*****.**", ResetPasswordToken = resetToken };
            var userList = new List<User> { foundUser }.AsQueryable();

            var userRepository = new Mock<IUserRepository>();
            userRepository.Setup(u => u.FindAll()).Returns(userList);

               var userService = ServiceMiniMart.CreateUserService(userRepository);

            // Act
            var user = userService.GetUserByResetToken(resetToken);

            // Assert
            Assert.AreEqual(foundUser, user);
        }
예제 #30
0
        public void GetUserById_Returns_Matching_User()
        {
            // Arrange
            const int userId = 123;
            var foundUser = new User { Email = "*****@*****.**" };

            var userRepository = new Mock<IUserRepository>();
            userRepository.Setup(u => u.FindOne(userId)).Returns(foundUser);

               var userService = ServiceMiniMart.CreateUserService(userRepository);

            // Act
            var user = userService.GetUserById(userId);

            // Assert
            Assert.AreEqual(foundUser, user);
        }
예제 #31
0
        public void GetUserByEmail_Returns_Matching_User()
        {
            // Arrange
            const string email = "*****@*****.**";
            var foundUser = new User { Email = email };
            var userList = new List<User> { foundUser }.AsQueryable();

            var userRepository = new Mock<IUserRepository>();
            userRepository.Setup(u => u.FindAll()).Returns(userList);

               var userService = ServiceMiniMart.CreateUserService(userRepository);

            // Act
            var user = userService.GetUserByEmail(email);

            // Assert
            Assert.AreEqual(foundUser, user);
        }
예제 #32
0
 partial void UpdateUser(User instance);