Exemplo n.º 1
0
        public void ShouldInsertWhenUserRepositoryIsValid()
        {
            var entity = FactoryUser.RandomCreate();

            _spacePlanningUnitOfWork.UserRepository.Add(entity);
            _spacePlanningUnitOfWork.Save();
            var retrived = _spacePlanningUnitOfWork.UserRepository.GetById(entity.UserId);

            Assert.IsTrue(retrived.Equals(entity));
        }
        public ActionResult RegFormHandle(string submitbutton, string strFName, string strLName, string strMail,
                                          string strPassword = "******")
        {
            // checking for existing user with same e-mail
            if (DataService.IsUser(strMail) || strFName.Length == 0 || strLName.Length == 0 || strMail.Length == 0)
            {
                // User with the same e-mail already exists
                return(RedirectToAction("WrongAccountForm", "User"));
            }
            else
            {
                FactoryAbstractUser userFactory = new FactoryUser();
                switch (submitbutton)
                {
                case "User":
                    User currUser = userFactory.Create(strFName, strLName, strMail, (int)UserType.User) as User;
                    DataService.UserToDataBase(currUser);

                    // Send notification about registration
                    return(RedirectToAction("Contact", "Email",
                                            new
                    {
                        strUserMail = strMail,
                        strMessage = "Your account (User) was successfully created",
                        strRedirectAction = "RegFormMessage",
                        strRedirectController = "User"
                    }));

                case "Librarian":
                    if (strPassword == "Password")
                    {
                        User currLibrarian =
                            userFactory.Create(strFName, strLName, strMail, (int)UserType.Librarian) as User;
                        DataService.UserToDataBase(currLibrarian);

                        // Send notification about registration
                        return(RedirectToAction("Contact", "Email",
                                                new
                        {
                            strUserMail = strMail,
                            strMessage = "Your account (Librarian) was successfully created",
                            strRedirectAction = "RegFormMessage",
                            strRedirectController = "User"
                        }));
                    }
                    break;

                default:
                    break;
                }

                // ТУТ и в подобных метсах, где может быть ошибка, надо возвращать страницу ошибки и все
                return(RedirectToAction("Index", "Entrance"));
            }
        }
Exemplo n.º 3
0
        public EntityUser GetUserByToken(string Token)
        {
            var data = base.DataContext.User.Where(p => p.Token == Token);

            if (data.Count() == 1)
            {
                return(FactoryUser.Get(data.Single()));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        public void ShoultDeleteWhenUserRepositoryIsValid()
        {
            var entity = FactoryUser.RandomCreate();

            _spacePlanningUnitOfWork.UserRepository.Add(entity);
            _spacePlanningUnitOfWork.Save();

            _spacePlanningUnitOfWork.UserRepository.Delete(entity);
            _spacePlanningUnitOfWork.Save();
            var retrived = _spacePlanningUnitOfWork.UserRepository.GetById(entity.UserId);

            Assert.IsNull(retrived);
        }
Exemplo n.º 5
0
        public EntityUser Get(int Id)
        {
            var data = base.DataContext.User.Where(p => p.UserID == Id);

            if (data.Count() == 1)
            {
                return(FactoryUser.Get(data.Single()));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 6
0
        public EntityUser GetUserName(string userName)
        {
            var data = base.DataContext.User.Where(p => p.UserName == userName);

            if (data.Count() == 1)
            {
                return(FactoryUser.Get(data.Single()));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 7
0
        public EntityUser GetEmail(string email)
        {
            var data = base.DataContext.User.Where(p => p.Email == email);

            if (data.Count() == 1)
            {
                return(FactoryUser.Get(data.Single()));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 8
0
        public void ShouldValidateSessionWhenDBContextIsValid()
        {
            User existingUser = FactoryUser.RandomCreate();
            User invalidUser  = FactoryUser.RandomCreate();

            invalidUser.Password = "******";
            _spacePlanningUnitOfWork.UserRepository.Add(existingUser);
            _spacePlanningUnitOfWork.Save();
            var store = new Mock <IUserStore <User> >();

            UserLockoutStoreSP lockout = new UserLockoutStoreSP(_spacePlanningUnitOfWork);
            var _userManager           = new UserManagerSP(lockout, null, null, null, null, null, null, null, null);

            Assert.True(_userManager.CheckPasswordAsync(existingUser, existingUser.Password).Result);
            Assert.False(_userManager.CheckPasswordAsync(existingUser, invalidUser.Password).Result);
        }
Exemplo n.º 9
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            string   name        = txt_name.Text;
            string   email       = txt_email.Text;
            string   password    = txt_password.Text;
            string   conPassword = txt_conPass.Text;
            string   gender      = RadioButtonList1.Text;
            DateTime birthdate   = Date_birth.SelectedDate.Date;
            string   pic         = FileUpload1.FileName;
            string   phone       = txt_phone.Text;
            string   address     = txt_address.Text;
            bool     isNull      = (birthdate == null);

            if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(conPassword) && !string.IsNullOrEmpty(gender) && !string.IsNullOrEmpty(pic) && !string.IsNullOrEmpty(phone) && !string.IsNullOrEmpty(address) && Date_birth.SelectedDate != null)
            {
                if (UserReposit.findEmail(email) == true)
                {
                    lbl_message.Text = "Your email is already registered";
                }
                else if (password != conPassword)
                {
                    lbl_message.Text = "Your confirm password is wrong";
                }
                else if (!pic.EndsWith(".jpg") && !pic.EndsWith(".png"))
                {
                    lbl_message.Text = "You must input .jpg or .png image";
                }
                else
                {
                    FileUpload1.SaveAs("D:\\UploadsUser\\" + FileUpload1.FileName);
                    string inputPath = "D:\\UploadsUser\\" + FileUpload1.FileName;
                    UserReposit.insertUser(FactoryUser.createUser(name, email, password, gender, birthdate, inputPath, phone, address));
                    Response.Redirect("Login.aspx");
                }
            }
            else
            {
                lbl_message.Text = "You must fill all data";
            }
        }
Exemplo n.º 10
0
        private void CreateAuditLog()
        {
            User user = FactoryUser.RandomCreate();

            _spacePlanningUnitOfWork.UserRepository.Add(user);

            LogLevel level = new LogLevel()
            {
                LogLevelId = 110, Name = "invalid user name"
            };

            _spacePlanningUnitOfWork.LogLevelRepository.Add(level);
            _spacePlanningUnitOfWork.Save();
            auditLog = new AuditLog()
            {
                AuditLogId = Guid.NewGuid(),
                CreateDate = DateTime.Now,
                Entry      = "Table:{ name:\"User\", oldData:\"email:[email protected]\", " +
                             "newData:\"[email protected]\"}",
                LevelId = 110,
                UserId  = user.UserId,
            };
        }
Exemplo n.º 11
0
 public List <EntityUser> GetActives()
 {
     return(FactoryUser.GetList(base.DataContext.User.Where(p => p.Status == true).ToList()));
 }
Exemplo n.º 12
0
 public static void InsertUser(Int32 roleid, String username, String password, String email, String gender, String status)
 {
     db.Users.Add(FactoryUser.InsUser(roleid, username, password, email, gender, status));
     db.SaveChanges();
 }
Exemplo n.º 13
0
 public List <EntityUser> GetAll()
 {
     return(FactoryUser.GetList(base.DataContext.User.ToList()));
 }
Exemplo n.º 14
0
 public static void RegisData(String Nama, String Email, String Password, String Gender, Int64 ID)
 {
     db.MsUsers.Add(FactoryUser.InitUser(Nama, Email, Password, Gender, ID));
     db.SaveChanges();
 }
Exemplo n.º 15
0
 public List <EntityUser> GetByIDs(List <int> IDS)
 {
     return(FactoryUser.GetList(base.DataContext.User.Where(p => IDS.Contains(p.UserID)).ToList()));
 }
Exemplo n.º 16
0
 public List <EntityUser> GetAllByID(int UserID)
 {
     return(FactoryUser.GetList(base.DataContext.User.Where(p => p.UserID == UserID).ToList()));
 }
Exemplo n.º 17
0
 public List <EntityUser> GetAllUserModuleProfile(int module, int profile)
 {
     return(FactoryUser.GetList(base.DataContext.User.Where(p => p.FK_ModuleID == module && p.ProfileID == profile).ToList()));
 }
Exemplo n.º 18
0
 public List <EntityUser> GetAllByModule(int module)
 {
     return(FactoryUser.GetList(base.DataContext.User.Where(p => p.FK_ModuleID == module).ToList()));
 }