コード例 #1
0
        public async Task <ActionResult> Index(User user)
        {
            using (Service1Client service = new Service1Client())
            {
                if (ModelState.IsValid)
                {
                    MD5    md5Hash = MD5.Create();
                    string md5Pass = ManageMD5.GetMd5Hash(md5Hash, user.Password);
                    user.Password = md5Pass;

                    if (user.Firstname != null && user.Lastname != null && user.Email != null && user.Password != null && user.Gender != null && user.Department != null && user.Title != null)
                    {
                        User userCreate = await service.CreateAsync(user);

                        if (userCreate != null)
                        {
                            FormsAuthentication.SetAuthCookie(userCreate.Id.ToString(), false);
                            return(RedirectToAction("index", "home"));
                        }
                        else
                        {
                            ModelState.AddModelError("", "Invalid form or user already exist");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "All fields are required.");
                    }
                }
                return(View());
            }
        }
コード例 #2
0
        public async Task <ActionResult> Index(User User)
        {
            using (Service1Client service = new Service1Client())
            {
                if (ModelState.IsValid)
                {
                    // Create MD5 Hash
                    MD5    md5Hash   = MD5.Create();
                    string md5Pass   = ManageMD5.GetMd5Hash(md5Hash, User.Password);
                    User   userExist = await service.GetUserByEmailAndPassAsync(User.Email, md5Pass);

                    if (userExist != null)
                    {
                        FormsAuthentication.SetAuthCookie(userExist.Id.ToString(), false);
                        return(RedirectToAction("index", "home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid email or password");
                    }
                }
                return(View());
            }
        }