Ejemplo n.º 1
0
        public ActionResult Change_password(FormCollection collection)
        {
            UserModels sv = new UserModels();
            C_User     it = new C_User();
            string     strBread;

            ViewBag.Title           = App_GlobalResources.Lang.strChangePassword + " | " + GeneralModels.GetContent(CommonGlobal.PageName, this.Lang);
            strBread                = "<li>" + App_GlobalResources.Lang.strChangePassword + "</li>";
            ViewBag.heading         = App_GlobalResources.Lang.strChangePassword;
            ViewBag.str_breadcrumbs = strBread;

            var login_view = new Login_view();

            this.TryUpdateModel(login_view);
            login_view.ParentAction     = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString();
            login_view.ParentController = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString();

            if (login_view.IsChange == 1 && string.IsNullOrEmpty(login_view.ConfirmCode) && (!string.IsNullOrEmpty(login_view.Password)) && (!string.IsNullOrEmpty(login_view.ConfirmPassword)))
            {
                ////user change password
                it = sv.GetUserbyUserName(login_view.UserName);
                if (it != null && MD5Extend.EncodePassword(login_view.OldPassword) == it.Password)
                {
                    if (login_view.Password == login_view.ConfirmPassword)
                    {
                        it.Password = MD5Extend.EncodePassword(login_view.Password);
                        sv.Update_User(it);
                        login_view.Message = App_GlobalResources.Lang.strMessageChangePasswordSuccess;
                    }
                    else
                    {
                        login_view.Message = App_GlobalResources.Lang.strMessageConfirmPassword;
                    }
                }
            }
            else if (login_view.IsChange == 0 && (!string.IsNullOrEmpty(login_view.ConfirmCode)) && (!string.IsNullOrEmpty(login_view.Password)) && (!string.IsNullOrEmpty(login_view.ConfirmPassword)))
            {
                ////client reset pasword
                if (MD5Extend.EncodePassword(login_view.Code + " " + login_view.UserName) == login_view.ConfirmCode)
                {
                    if (login_view.Password == login_view.ConfirmPassword)
                    {
                        it          = sv.GetUserbyUserName(login_view.UserName);
                        it.Password = MD5Extend.EncodePassword(login_view.Password);
                        sv.Update_User(it);
                        login_view.Message = App_GlobalResources.Lang.strMessageChangePasswordSuccess;
                    }
                    else
                    {
                        login_view.Message = App_GlobalResources.Lang.strMessageConfirmPassword;
                    }
                }
                else
                {
                    login_view.Message = App_GlobalResources.Lang.strMessageErrorConfirmCode;
                }
            }

            return(this.PartialView("../page/change_password", login_view));
        }
Ejemplo n.º 2
0
        public IActionResult Post([FromBody] AdminUserView userView)
        {
            IActionResult response   = null;
            UserModels    userModels = new UserModels();
            User          user       = null;
            var           mess       = string.Empty;
            string        rt         = string.Empty;

            user = new User
            {
                Username  = userView.Username,
                Online    = userView.Online,
                Role      = userView.Role,
                Password  = MD5Extend.EncodePassword(userView.Password),
                Ip        = userView.Ip,
                LastLogin = null
            };

            rt = userModels.AddUser(user, userView);

            if (rt.Length > 0)
            {
                response = Json(new { code = Constant.Success, message = Constant.MessageCreateCompleted });
            }
            else
            {
                response = Json(new { code = Constant.Fail, message = Constant.MessageCreateUncompleted });
            }

            return(response);
        }
Ejemplo n.º 3
0
        public IActionResult ChangePassword([FromBody] ChangePasswordView login)
        {
            UserModels    sv       = new UserModels();
            IActionResult response = null;

            var identity = (ClaimsIdentity)User.Identity;
            IEnumerable <Claim> claims = identity.Claims;
            var userLogin = claims.FirstOrDefault(c => c.Type == ClaimTypes.Email).Value;

            if (!string.IsNullOrEmpty(login.Password) && !string.IsNullOrEmpty(login.ConfirmPassword))
            {
                // user change password
                User user = sv.GetUserbyUserName(userLogin);
                if (user != null && MD5Extend.EncodePassword(login.OldPassword) == user.Password)
                {
                    if (login.Password == login.ConfirmPassword)
                    {
                        user.Password = MD5Extend.EncodePassword(login.Password);
                        sv.UpdateUserPassword(user);
                        response = Json(new { code = Constant.Success, message = Constant.MessageUpdateCompleted });
                    }
                    else
                    {
                        response = Json(new { code = Constant.Fail, message = Constant.MessageConfirmPassword });
                    }
                }
            }
            else
            {
                response = Json(new { code = Constant.NotExist, message = Constant.MessageNotExist });
            }

            return(response);
        }
Ejemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            string input  = this.textBox1.Text;
            bool   low    = this.comboBox1.SelectedIndex == 0;
            string result = input;

            if (this.radioButton16.Checked)
            {
                result = MD5Extend.MD5Encrypt16(input);
            }
            else if (this.radioButton32.Checked)
            {
                result = MD5Extend.MD5Encrypt(input);
            }
            else
            {
                result = MD5Extend.MD5Encrypt64(input);
            }
            if (low)
            {
                result = result.ToLower();
            }
            else
            {
                result = result.ToUpper();
            }
            this.textBox2.Text = result;
        }
Ejemplo n.º 5
0
        private UserInfo Authenticate(LoginView login, out User user, out Role role)
        {
            UserModels sv  = new UserModels();
            UserInfo   iit = new UserInfo();

            user = sv.GetUserbyUserName(login.UserName);
            if (user != null && MD5Extend.EncodePassword(login.Password) == user.Password && user.Online == true)
            {
                role = sv.GetRolebyId(user.Role);
                iit  = sv.GetUserInforByEmail(user.Username);
                if (iit != null)
                {
                    return(iit);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                role = null;
                return(null);
            }
        }
Ejemplo n.º 6
0
        public ActionResult Change_password(FormCollection collection)
        {
            UserModels sv = new UserModels();
            C_User     it = new C_User();

            var login_view = new Login_view();

            this.TryUpdateModel(login_view);
            login_view.Parent_action     = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString();
            login_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString();

            if (login_view.Is_change == 1 && string.IsNullOrEmpty(login_view.Confirm_code))
            {
                ////user change password
                it = sv.GetUserbyUserName(login_view.User_name);
                if (it != null && MD5Extend.EncodePassword(login_view.Old_password) == it.Password)
                {
                    if (login_view.Password == login_view.Confirm_password)
                    {
                        it.Password = MD5Extend.EncodePassword(login_view.Password);
                        sv.Update_User(it);
                        login_view.Message = App_GlobalResources.Lang.strMessageChangePasswordSuccess;
                    }
                    else
                    {
                        login_view.Message = App_GlobalResources.Lang.strMessageConfirmPassword;
                    }
                }

                return(this.Redirect(login_view.Return_url));
            }
            else if (login_view.Is_change == 0 && (!string.IsNullOrEmpty(login_view.Confirm_code)))
            {
                ////client reset pasword
                if (MD5Extend.EncodePassword(login_view.Code + " " + login_view.User_name) == login_view.Confirm_code)
                {
                    if (login_view.Password == login_view.Confirm_password)
                    {
                        it          = sv.GetUserbyUserName(login_view.User_name);
                        it.Password = MD5Extend.EncodePassword(login_view.Password);
                        sv.Update_User(it);
                        login_view.Message = App_GlobalResources.Lang.strMessageChangePasswordSuccess;
                    }
                    else
                    {
                        login_view.Message = App_GlobalResources.Lang.strMessageConfirmPassword;
                    }
                }
                else
                {
                    login_view.Message = App_GlobalResources.Lang.strMessageErrorConfirmCode;
                }

                return(this.PartialView("../page/change_password", login_view));
            }
            else
            {
                return(this.PartialView("../page/change_password", login_view));
            }
        }
Ejemplo n.º 7
0
        public ActionResult Login(string user_name, string password, string return_url, bool?remember_me)
        {
            var        login_view = new Login_view();
            UserModels sv         = new UserModels();
            C_User     it         = new C_User();

            login_view.Parent_action     = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString();
            login_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString();
            it = sv.GetUserbyUserName(user_name);
            if (remember_me == null)
            {
                remember_me = false;
            }

            if (it != null && MD5Extend.EncodePassword(password) == it.Password)
            {
                this.Session["mem"]  = user_name;
                this.Session["role"] = it.Role.ToString();
                it.IP        = HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString();
                it.LastLogin = DateTime.Now;

                ////Client only : If Online = true is client online else is offline
                if (it.Role.ToString() == "2")
                {
                    login_view.Message    = App_GlobalResources.Lang.mess403;
                    login_view.Return_url = return_url;

                    return(this.PartialView("../page/login", login_view));
                }
                else if (it.Role.ToString() == "1" && it.Online == true)
                {
                    ////Admin only : If Online = true is active else is disable login
                    sv.Update_User(it);
                    this.Session["acc"] = user_name;
                    this.SetAccountCookies(user_name, user_name, it.Role.ToString(), 12);

                    return(this.RedirectToAction("index", "dashboard", new { area = "admin" }));
                }
                else
                {
                    login_view.Message    = App_GlobalResources.Lang.mess403;
                    login_view.Return_url = return_url;
                    return(this.PartialView("../page/login", login_view));
                }
            }
            else
            {
                login_view.Message    = App_GlobalResources.Lang.messLoginFail;
                login_view.Return_url = return_url;
                return(this.PartialView("../page/login", login_view));
            }
        }
Ejemplo n.º 8
0
        public ActionResult Login(string user_name, string password, string return_url)
        {
            var        login_view = new Login_view();
            UserModels sv         = new UserModels();
            C_User     it         = new C_User();
            C_UserInfo iit        = new C_UserInfo();

            login_view.ParentAction     = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString();
            login_view.ParentController = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString();
            it = sv.GetUserbyUserName(user_name);
            if (it != null && MD5Extend.EncodePassword(password) == it.Password)
            {
                iit = sv.GetUserInforByEmail(user_name);
                if (iit != null)
                {
                    this.Session["acc"]  = iit.FName + ' ' + iit.LName;
                    this.Session["mem"]  = user_name;
                    this.Session["role"] = it.Role.ToString();
                    this.SetAccountCookies(iit.FName, user_name, it.Role.ToString(), 6);
                    it.Online    = true;
                    it.IP        = HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString();
                    it.LastLogin = DateTime.Now;
                    sv.Update_User(it);
                    if (it.Role.ToString() == "2" && it.Online == true)
                    {
                        if (this.Session["acc"] == null)
                        {
                            this.Session["acc"] = it.Username;
                        }

                        if (Url.IsLocalUrl(return_url))
                        {
                            return(this.Redirect(return_url));
                        }
                        else
                        {
                            return(this.RedirectToAction("my_account", "account"));
                        }
                    }
                    else if (it.Role.ToString() == "1" && it.Online == true)
                    {
                        return(this.RedirectToAction("index", "dashboard", new { area = "admin" }));
                    }
                    else
                    {
                        login_view.Message   = App_GlobalResources.Lang.mess403;
                        login_view.ReturnUrl = return_url;
                        return(this.PartialView("../page/login", login_view));
                    }
                }
                else
                {
                    login_view.Message   = App_GlobalResources.Lang.mess403;
                    login_view.ReturnUrl = return_url;
                    return(this.PartialView("../page/login", login_view));
                }
            }
            else
            {
                login_view.Message   = App_GlobalResources.Lang.messLoginFail;
                login_view.ReturnUrl = return_url;
                return(this.PartialView("../page/login", login_view));
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Instagrams the callback.
        /// </summary>
        /// <returns>the Instagram Call back</returns>
        public ActionResult InstagramCallback()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["code"]))
            {
                string code = Request.QueryString["code"];
                try
                {
                    NameValueCollection parameters = new NameValueCollection();
                    parameters.Add("client_id", Util.GetConfigValue("AppInstagramID", string.Empty));
                    parameters.Add("client_secret", Util.GetConfigValue("AppInstagramSecret", string.Empty));
                    parameters.Add("grant_type", "authorization_code");
                    parameters.Add("redirect_uri", Util.GetConfigValue("AppIstagramReturn", string.Empty));
                    parameters.Add("code", code);

                    WebClient client   = new WebClient();
                    var       result   = client.UploadValues("https://api.instagram.com/oauth/access_token", "POST", parameters);
                    var       response = System.Text.Encoding.Default.GetString(result);

                    //// deserializing nested JSON string to object
                    var    javascriptResult = (JObject)JsonConvert.DeserializeObject(response);
                    string accessToken      = (string)javascriptResult["access_token"];
                    string id = (string)javascriptResult["user"]["id"];
                    string username_client = (string)javascriptResult["user"]["username"];
                    string fullname_client = (string)javascriptResult["user"]["full_name"];

                    ////This code register id and access token to get on client side
                    ////Page.ClientScript.RegisterStartupScript(this.GetType(), "GetToken", "<script>var instagramaccessid=\"" + @"" + id + "" + "\"; var instagramaccesstoken=\"" + @"" + accessToken + "" + "\";</script>");
                    UserModels sv  = new UserModels();
                    C_User     it  = new C_User();
                    C_UserInfo iit = new C_UserInfo();
                    it = sv.GetUserbyUserName(username_client);
                    if (it == null)
                    {
                        it = new C_User();
                        string rt     = string.Empty;
                        bool   infors = false;
                        it.Username  = username_client;
                        it.Role      = 2;
                        it.Password  = MD5Extend.EncodePassword("123456");
                        it.Online    = true;
                        it.IP        = HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString();
                        it.LastLogin = DateTime.Now;
                        rt           = sv.Add_User(it);

                        iit.FName = fullname_client;
                        iit.Email = username_client;
                        ////iit.LName = middlename;
                        iit.DateRegister = DateTime.Now;
                        ////iit.EventId = string.IsNullOrEmpty(ids) != false ? int.Parse(ids) : 0;
                        iit.Note = "Instagram login";
                        infors   = sv.Add_User_Infor(iit);

                        if (rt.Length > 0 && infors == true)
                        {
                            ////register_view.message = Lang.strMessageLogin;
                            this.Session["acc"]  = iit.FName;
                            this.Session["mem"]  = rt;
                            this.Session["role"] = it.Role.ToString();
                            this.SetAccountCookies(iit.FName, rt, it.Role.ToString(), 6);
                        }
                    }
                    else
                    {
                        iit = sv.GetUserInforByEmail(username_client);
                        this.Session["acc"]  = iit.FName;
                        this.Session["mem"]  = it.Username;
                        this.Session["role"] = it.Role.ToString();
                        this.SetAccountCookies(iit.FName, it.Username, it.Role.ToString(), 6);
                        it.Online    = true;
                        it.IP        = HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString();
                        it.LastLogin = DateTime.Now;
                        sv.Update_User(it);
                    }

                    if (this.Session["Instagram_return"] != null && Url.IsLocalUrl(this.Session["Instagram_return"].ToString()))
                    {
                        return(this.Redirect(this.Session["Instagram_return"].ToString()));
                    }
                    else
                    {
                        return(this.RedirectToAction("index", "home"));
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                return(this.RedirectToAction("index", "home"));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Google the callback.
        /// </summary>
        /// <returns>Google Call back</returns>
        public ActionResult GoogleCallback()
        {
            GoogleConnect.ClientId     = Util.GetConfigValue("AppGoogleID", string.Empty);
            GoogleConnect.ClientSecret = Util.GetConfigValue("AppGoogleSecret", string.Empty);

            if (!string.IsNullOrEmpty(Request.QueryString["code"]))
            {
                string        code    = Request.QueryString["code"];
                string        json    = GoogleConnect.Fetch("me", code);
                GoogleProfile profile = new JavaScriptSerializer().Deserialize <GoogleProfile>(json);

                UserModels sv  = new UserModels();
                C_User     it  = new C_User();
                C_UserInfo iit = new C_UserInfo();
                it = sv.GetUserbyUserName(profile.Emails.Find(email => email.Type == "account").Value);
                if (it == null)
                {
                    it = new C_User();
                    string rt     = string.Empty;
                    bool   infors = false;
                    it.Username  = profile.Emails.Find(email => email.Type == "account").Value;
                    it.Role      = 2;
                    it.Password  = MD5Extend.EncodePassword("123456");
                    it.Online    = true;
                    it.IP        = HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString();
                    it.LastLogin = DateTime.Now;
                    rt           = sv.Add_User(it);

                    iit.FName = profile.DisplayName;
                    iit.Email = profile.Emails.Find(email => email.Type == "account").Value;
                    ////iit.LName = middlename;
                    iit.DateRegister = DateTime.Now;
                    ////iit.EventId = string.IsNullOrEmpty(ids) != false ? int.Parse(ids) : 0;
                    iit.Note = "Google login";
                    infors   = sv.Add_User_Infor(iit);

                    if (rt.Length > 0 && infors == true)
                    {
                        ////register_view.message = Lang.strMessageLogin;
                        this.Session["acc"]  = iit.FName;
                        this.Session["mem"]  = rt;
                        this.Session["role"] = it.Role.ToString();
                        this.SetAccountCookies(iit.FName, rt, it.Role.ToString(), 6);
                    }
                }
                else
                {
                    iit = sv.GetUserInforByEmail(profile.Emails.Find(email => email.Type == "account").Value);
                    this.Session["acc"]  = iit.FName;
                    this.Session["mem"]  = it.Username;
                    this.Session["role"] = it.Role.ToString();
                    this.SetAccountCookies(iit.FName, it.Username, it.Role.ToString(), 6);
                    it.Online    = true;
                    it.IP        = HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString();
                    it.LastLogin = DateTime.Now;
                    sv.Update_User(it);
                }

                ////lblId.Text = profile.Id;
                ////lblName.Text = profile.DisplayName;
                ////lblEmail.Text = profile.Emails.Find(email => email.Type == "account").Value;
                ////lblGender.Text = profile.Gender;
                ////lblType.Text = profile.ObjectType;
                ////ProfileImage.ImageUrl = profile.Image.Url;
                if (Request.QueryString["error"] == "access_denied")
                {
                    ////login fail
                    logger.Error("Error requesting OAuth user data from Google:" + Request.QueryString["error"]);
                }

                if (this.Session["Google_return"] != null && Url.IsLocalUrl(this.Session["Google_return"].ToString()))
                {
                    return(this.Redirect(Session["Google_return"].ToString()));
                }
                else
                {
                    return(this.RedirectToAction("index", "home"));
                }
            }
            else
            {
                return(this.RedirectToAction("index", "home"));
            }
        }
Ejemplo n.º 11
0
        public ActionResult Forgot_password(FormCollection collection)
        {
            OrderModels   orderModels = new OrderModels();
            WebInfoModels web_infor   = new Models.WebInfoModels();
            UserModels    sv          = new UserModels();
            C_User        it          = new C_User();
            var           login_view  = new Login_view();

            this.TryUpdateModel(login_view);
            string strBread;

            ViewBag.Title           = App_GlobalResources.Lang.strForgotPassword + " | " + GeneralModels.GetContent(CommonGlobal.PageName, this.Lang);
            strBread                = "<li>" + App_GlobalResources.Lang.strForgotPassword + "</li>";
            ViewBag.heading         = App_GlobalResources.Lang.strForgotPassword;
            ViewBag.str_breadcrumbs = strBread;

            login_view.ParentAction     = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString();
            login_view.ParentController = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString();
            login_view.ReturnUrl        = Url.Action("login", "account");

            ////check user_name or email
            it = sv.GetUserbyUserName(login_view.UserName);
            if (it != null)
            {
                login_view.Message = App_GlobalResources.Lang.strMessageSendNewPassword;
                string code = GetCodeUniqueKey(8); ////orderModels.getOrderCodeUnique();
                string link = Url.Action("change_password", "account", new { cfcode = MD5Extend.EncodePassword(code + " " + login_view.UserName) });
                //// send email to client
                var strBody_email_client = GeneralModels.GetContent(CommonGlobal.EmailConfirmForgotPassword, Lang).ToString(); ////get from email template
                strBody_email_client = strBody_email_client.Replace("{domain}", Util.GetConfigValue("Domain", Request.UserHostName).ToString());
                strBody_email_client = strBody_email_client.Replace("{store_name}", GeneralModels.GetContent(CommonGlobal.PageName, Lang).ToString());
                strBody_email_client = strBody_email_client.Replace("{email}", web_infor.GetContent(CommonGlobal.Email).ToString());
                strBody_email_client = strBody_email_client.Replace("{email_client}", login_view.UserName);
                strBody_email_client = strBody_email_client.Replace("{code}", code);
                strBody_email_client = strBody_email_client.Replace("{link}", Util.GetConfigValue("Domain", Request.UserHostName).ToString() + link);

                CommonGlobal.SendMail(login_view.UserName, App_GlobalResources.Lang.strSubjectConfirmForgotPassword + "- " + Util.GetConfigValue("Domain", Request.UserHostName).ToString(), strBody_email_client);
            }
            else
            {
                login_view.Message = App_GlobalResources.Lang.strMessageForgotPassword;
            }

            return(this.PartialView("../page/forgot_password", login_view));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Facebook the callback.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <returns>Facebook Call back</returns>
        public ActionResult FacebookCallback(string code)
        {
            var     fb     = new Facebook.FacebookClient();
            dynamic result = fb.Post("oauth/access_token", new { client_id = Util.GetConfigValue("AppFaceBookID", string.Empty), client_secret = Util.GetConfigValue("AppFacebookSecret", string.Empty), redirect_uri = this.RedirectUri.AbsoluteUri, code = code });

            var accessToken = result.access_token;

            //// Store the access token in the session for farther use
            this.Session["AccessToken"] = accessToken;

            //// update the facebook client with the access token so
            //// we can make requests on behalf of the user
            fb.AccessToken = accessToken;

            //// Get the user's information
            dynamic me         = fb.Get("me?fields=first_name,middle_name,last_name,id,email");
            string  email      = me.email;
            string  firstname  = me.first_name;
            string  middlename = me.middle_name;
            string  lastname   = me.last_name;
            string  ids        = me.id;

            //// Set the auth cookie
            ////FormsAuthentication.SetAuthCookie(email, false);

            UserModels sv  = new UserModels();
            C_User     it  = new C_User();
            C_UserInfo iit = new C_UserInfo();

            it = sv.GetUserbyUserName(email);
            if (it == null)
            {
                it = new C_User();
                string rt     = string.Empty;
                bool   infors = false;
                it.Username  = email;
                it.Role      = 2;
                it.Password  = MD5Extend.EncodePassword("123456");
                it.Online    = true;
                it.IP        = HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString();
                it.LastLogin = DateTime.Now;
                rt           = sv.Add_User(it);

                iit.FName        = firstname;
                iit.Email        = email;
                iit.LName        = middlename;
                iit.DateRegister = DateTime.Now;
                iit.EventId      = string.IsNullOrEmpty(ids) != false?int.Parse(ids) : 0;

                iit.Note = "Facebook login";
                infors   = sv.Add_User_Infor(iit);

                if (rt.Length > 0 && infors == true)
                {
                    ////register_view.message = Lang.strMessageLogin;
                    this.Session["acc"]  = iit.FName;
                    this.Session["mem"]  = rt;
                    this.Session["role"] = it.Role.ToString();
                    this.SetAccountCookies(iit.FName, rt, it.Role.ToString(), 6);
                }
            }
            else
            {
                iit = sv.GetUserInforByEmail(email);
                this.Session["acc"]  = iit.FName;
                this.Session["mem"]  = it.Username;
                this.Session["role"] = it.Role.ToString();
                this.SetAccountCookies(iit.FName, it.Username, it.Role.ToString(), 6);
                it.Online    = true;
                it.IP        = HttpContext.Request.ServerVariables["REMOTE_ADDR"].ToString();
                it.LastLogin = DateTime.Now;
                sv.Update_User(it);
            }

            if (this.Session["FaceBook_return"] != null && Url.IsLocalUrl(this.Session["FaceBook_return"].ToString()))
            {
                return(this.Redirect(Session["FaceBook_return"].ToString()));
            }
            else
            {
                return(this.RedirectToAction("index", "home"));
            }
        }
Ejemplo n.º 13
0
        public ActionResult Register(FormCollection collection)
        {
            var register_view = new Register_view();

            this.TryUpdateModel(register_view);
            UserModels sv  = new UserModels();
            C_User     it  = new C_User();
            C_UserInfo iit = new C_UserInfo();

            register_view.Parent_action     = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString();
            register_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString();
            if (HttpContext.Session["captchastring"] != null && register_view.Code == HttpContext.Session["captchastring"].ToString())
            {
                if (register_view.Password != register_view.Confirm_password)
                {
                    register_view.Message = App_GlobalResources.Lang.messConfirmPassword;
                    return(this.PartialView("../page/register", register_view));
                }

                if (sv.GetUserbyUserName(register_view.Email) != null)
                {
                    register_view.Message = App_GlobalResources.Lang.messExistsEmail;
                    return(this.PartialView("../page/register", register_view));
                }

                string rt     = string.Empty;
                bool   infors = false;
                it.Username  = register_view.Email;
                it.Role      = 2;
                it.Password  = MD5Extend.EncodePassword(register_view.Password);
                it.IP        = "not login";
                it.Online    = true;
                it.LastLogin = DateTime.Now;
                rt           = sv.Add_User(it);

                iit.FName = register_view.FirstName;
                iit.Email = register_view.Email;
                infors    = sv.Add_User_Infor(iit);

                if (rt.Length > 0 && infors == true)
                {
                    register_view.Message = App_GlobalResources.Lang.strMessageLogin;
                    this.Session["acc"]   = register_view.Email;
                    this.Session["mem"]   = rt;
                    this.Session["role"]  = it.Role.ToString();
                    this.SetAccountCookies(register_view.Email, rt, it.Role.ToString(), 6);

                    if (!string.IsNullOrEmpty(register_view.Return_url))
                    {
                        return(this.Redirect(register_view.Return_url));
                    }
                    else
                    {
                        return(this.RedirectToAction("index", "home"));
                    }
                }
                else
                {
                    register_view.Message = App_GlobalResources.Lang.messErrorRegister;

                    return(this.PartialView("../page/register", register_view));
                }
            }
            else
            {
                register_view.Message = App_GlobalResources.Lang.messCaptcha;

                return(this.PartialView("../page/register", register_view));
            }
        }
Ejemplo n.º 14
0
        public ActionResult Change_user(FormCollection collection)
        {
            UserModels    userModels = new UserModels();
            C_User        cuser      = null;
            StringBuilder sb         = new StringBuilder();
            var           user_view  = new Web.Areas.Admin.ViewModels.User_view();

            this.TryUpdateModel(user_view);
            string rt       = string.Empty;
            bool   is_valid = true;

            if (!string.IsNullOrEmpty(user_view.Username))
            {
                cuser = userModels.GetUserbyUserName(user_view.Username);
            }

            ////validation server
            if (string.IsNullOrEmpty(user_view.Username))
            {
                is_valid = false;
                if (user_view.Message == string.Empty)
                {
                    user_view.Message = "Bạn phải nhập User Name";
                }
            }

            ////UserName duplicate Admin
            if (user_view.Username == "Admin")
            {
                is_valid = false;
                if (user_view.Message == string.Empty)
                {
                    user_view.Message = "Bạn không thể tạo Admin";
                }
            }
            ////Link tab
            sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "list_user", ctrl = "adminUser", type = user_view.Type, page = "1" }) + "\"><span><span>Danh sách Admin</span></span></a></li>");
            if (!string.IsNullOrEmpty(user_view.Username) && user_view.Type_act == CommonGlobal.Edit)
            {
                sb.Append("<li class=\"active\"><a href=\"#\"><span><span>" + cuser.Username + "</span></span></a></li>");
            }
            else
            {
                sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm mới</span></span></a></li>");
                ////validation password
                if (string.IsNullOrEmpty(user_view.Password))
                {
                    is_valid = false;
                    if (user_view.Message == string.Empty)
                    {
                        user_view.Message = "Bạn phải nhập mật khẩu";
                    }
                }

                if (string.IsNullOrEmpty(user_view.ConfirmPassword))
                {
                    is_valid = false;
                    if (user_view.Message == string.Empty)
                    {
                        user_view.Message = "Bạn phải xác nhận mật khẩu";
                    }
                }

                if (user_view.Password != user_view.ConfirmPassword)
                {
                    is_valid = false;
                    if (user_view.Message == string.Empty)
                    {
                        user_view.Message = "Bạn phải xác nhận mật khẩu";
                    }
                }
            }

            sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "list_user_permission", ctrl = "adminUser", type = user_view.Type, user_name = user_view.Username, page = "1" }) + "\"><span><span>Permission</span></span></a></li>");
            user_view.Html_link_tab = sb.ToString();
            if (!is_valid)
            {
                return(this.PartialView("../control/change_user", user_view));
            }

            cuser          = new C_User();
            cuser.Username = user_view.Username;
            cuser.Online   = user_view.Online;

            if (cuser.Online == true)
            {
                user_view.Online      = true;
                user_view.Online_text = "checked='checked'";
            }
            else
            {
                user_view.Online      = false;
                user_view.Online_text = string.Empty;
            }

            if (!string.IsNullOrEmpty(user_view.Username) && user_view.Type_act == CommonGlobal.Edit)
            {
                rt = userModels.Update_User(cuser);
            }
            else
            {
                cuser.Role      = 1;
                cuser.Password  = MD5Extend.EncodePassword(user_view.Password);
                cuser.IP        = "not login";
                cuser.Online    = true;
                cuser.LastLogin = null;
                rt = userModels.Add_User(cuser);
            }

            if (rt.Length > 0)
            {
                user_view.Message  = "Cập nhật thành công!";
                user_view.Username = rt;
                user_view.Type_act = CommonGlobal.Edit;
            }
            else
            {
                user_view.Message = "Cập nhật không thành công!";
            }

            return(this.PartialView("../control/change_user", user_view));
        }