コード例 #1
0
        public ActionResult Edit(User data)
        {
            if (ModelState.IsValid)
            {
                User obj = GetUserSession();
                obj.UserId = data.UserId;
                obj.FName  = data.FName;
                obj.LName  = data.LName;
                obj.Email  = data.Email;

                obj.Password    = repositoryDEncryption.Encrypt(data.Password);
                obj.Create_time = data.Create_time;
                obj.Update_Time = DateTime.Now;//Need solution for this field no need any value
                obj.Last_Login  = data.Last_Login;
                obj.RoleId      = data.RoleId;
                repositoryUser.Save(obj);
                int?Newid = obj.UserId;
                if (obj != null)
                {
                    TempData["message"] = string.Format("{0} was Edited Successfully", obj.FName + " " + obj.LName);
                }
                return(RedirectToAction("Details", new { Id = Newid }));
            }
            return(View());
        }
コード例 #2
0
        public ActionResult UpdateEmailSetting(EmailSetting data)
        {
            EmailSetting obj = GetEmailSettingSession();

            var identity       = (HttpContext.User as MyPrincipal).Identity as MyIdentity;
            int _CurrentUserId = Convert.ToInt32(identity.User.UserId);

            if (_CurrentUserId == 0)
            {
                //becouse Sometime id = 0 ?????!!!! maybe session die???????
                return(View(data));
            }
            if (ModelState.IsValid)
            {
                obj.Id              = data.Id;
                obj.SMTP_Server     = data.SMTP_Server;
                obj.Sender          = data.Sender;
                obj.SMTPServer_Port = data.SMTPServer_Port;
                obj.UserName        = data.UserName;
                string HashPassword = repositoryDEncrption.Encrypt(data.Password);
                obj.Password    = HashPassword;
                obj.EnableSSL   = data.EnableSSL;
                obj.Last_Update = DateTime.Now;
                obj.UserId      = _CurrentUserId;

                repositoryEmailSetting.Save(obj);
                if (obj != null)
                {
                    if (data.Id == 0)//New or Update
                    {
                        TempData["message"] = string.Format("Added Successfully");
                    }
                    else
                    {
                        TempData["message"] = string.Format("Edited Successfully");
                    }
                }
                return(RedirectToAction("EmailSettingDetails", "Setting", data));//SamePlace
            }

            return(View(data));
        }
コード例 #3
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            bool isCapthcaValid = ValidateCaptcha(Request["g-recaptcha-response"]);

            if (ModelState.IsValid)
            {
                if (isCapthcaValid)
                {
                    // string encryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(model.Password, "SHA1");
                    string EncryptedPW = repositoryDEncryption.Encrypt(model.Password.TrimEnd());
                    User   _User       = null;

                    var IsValidUser = repositoryMemberShipProvider.ValidateUser(model.Email.TrimEnd(), EncryptedPW);

                    if (IsValidUser)
                    {
                        _User = repositoryUser.UserIEmum.Where(a => a.Email.Equals(model.Email.TrimEnd())).FirstOrDefault();
                        ///Last Login///
                        ///
                        _User.Last_Login = DateTime.Now;
                        repositoryUser.Save(_User);
                        ///
                    }

                    if (_User != null)
                    {
                        JavaScriptSerializer js          = new JavaScriptSerializer();
                        string data                      = js.Serialize(_User);
                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, _User.Email, DateTime.Now, DateTime.Now.AddMinutes(30), model.RememberMe, data);
                        string     encToken              = FormsAuthentication.Encrypt(ticket);
                        HttpCookie authoCookies          = new HttpCookie(FormsAuthentication.FormsCookieName, encToken);
                        Response.Cookies.Add(authoCookies);
                        if (_User.RoleId == 1)                                                      //Admin
                        {
                            return(Redirect(returnUrl ?? Url.Action("Index", "Account")));          //Admin dash
                        }
                        else if (_User.RoleId == 3)                                                 //SuperUser
                        {
                            return(Redirect(returnUrl ?? Url.Action("SuperUserIndex", "Account"))); //SuperUser Dash
                        }
                        return(Redirect(returnUrl ?? Url.Action("Index", "Home")));                 //User HomePage
                    }
                }
                else
                {
                    ModelState.AddModelError("", "You have put wrong Captcha,Please ensure the authenticity !!!");
                    ModelState.Remove("Password");

                    //Should load sitekey again
                    return(View());
                }
            }
            else
            {
                ModelState.AddModelError("", "Incorrect username or password");
                ModelState.Remove("Password");

                //Should load sitekey again
                return(View());
            }
            return(View());
        }