Exemplo n.º 1
0
        public JsonResult Delete(int id)
        {
            response r = new response();

            string conStr            = Session["conStr"].ToString(); //ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString;
            int    _CURENT_USER_ID   = Convert.ToInt32(Session["CURENT_USER_ID"]);
            UtilizatoriRepository ur = new UtilizatoriRepository(_CURENT_USER_ID, conStr);
            Utilizator            u  = new Utilizator(_CURENT_USER_ID, conStr, id);

            r = u.Delete();
            return(Json(r, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public JsonResult SetPassword(int id_utilizator, string password, string confirmPassword)
        {
            response r = new response();

            if (password != confirmPassword) // alte validari aici !!!
            {
                r = new response(false, "Parolele nu coincid!", null, null, new List <Error>()
                {
                    ErrorParser.ErrorMessage("passwordsDontMatch")
                });
                return(Json(r, JsonRequestBehavior.AllowGet));
            }
            string conStr            = Session["conStr"].ToString(); //ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString;
            int    _CURENT_USER_ID   = Convert.ToInt32(Session["CURENT_USER_ID"]);
            UtilizatoriRepository ur = new UtilizatoriRepository(_CURENT_USER_ID, conStr);

            r = ur.SetPassword(id_utilizator, password);
            return(Json(r, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public JsonResult Save(Utilizator Utilizator)
        {
            response r = new response();

            string conStr            = Session["conStr"].ToString(); //ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString;
            int    _CURENT_USER_ID   = Convert.ToInt32(Session["CURENT_USER_ID"]);
            UtilizatoriRepository ur = new UtilizatoriRepository(_CURENT_USER_ID, conStr);
            Utilizator            u  = new Utilizator(_CURENT_USER_ID, conStr);

            PropertyInfo[] pis = Utilizator.GetType().GetProperties();
            foreach (PropertyInfo pi in pis)
            {
                pi.SetValue(u, pi.GetValue(Utilizator));
            }
            if (Utilizator.ID == null) // insert
            {
                r = u.Insert();
            }
            else // update
            {
                r = u.Update();
            }
            return(Json(r, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 4
0
        public ActionResult Login(LoginJson model, string returnUrl, string submitCode)
        {
            string culture = "en-US";

            if (Session["Culture"] != null)
            {
                culture = Session["Culture"].ToString();
            }
            Session.RemoveAll();
            Session["Culture"] = culture;

            if (submitCode == "Retrimite codul")
            {
                model.Code = null;
                //string rnd = "1234"; // pt. test

                Utilizator u         = (Utilizator)TempData["tempLogin"];
                Random     generator = new Random();
                string     rnd       = generator.Next(0, 1000000).ToString("D6");
                SendVerificationCode(EmailProfiles.AwsCereriSES, u.EMAIL, rnd);
                TempData.Clear();
                TempData["tempLogin"]                 = u;
                TempData["verificationCode"]          = rnd;
                TempData["verificationCodeIssueTime"] = DateTime.Now;
                return(View("Login", new LoginJson()));
            }


            if ((TempData["tempLogin"] == null || String.IsNullOrWhiteSpace(TempData["tempLogin"].ToString())) && String.IsNullOrWhiteSpace(model.Username))
            {
                ModelState.AddModelError("", socisaV2.Resources.ErrorMessagesResx.EMPTY_USERNAME);
            }
            if ((TempData["tempLogin"] == null || String.IsNullOrWhiteSpace(TempData["tempLogin"].ToString())) && String.IsNullOrWhiteSpace(model.Password))
            {
                ModelState.AddModelError("", socisaV2.Resources.ErrorMessagesResx.EMPTY_PASSWORD);
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (Session["conStr"] == null)                                                                                                                                                                                                                                                                                                                                                                                                             // pt. relogin dupa expirare sesiune sau inactivitate
            {
                string conStr = Server.MapPath("~").ToLower().IndexOf("test") > 0 ? CommonFunctions.StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["MySQLConnectionString_test"].ConnectionString, CommonFunctions.StringCipher.RetrieveKey()) : CommonFunctions.StringCipher.Decrypt(System.Configuration.ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString, CommonFunctions.StringCipher.RetrieveKey()); // separam socisa de socisa_test
                Session["conStr"] = conStr;
            }
            UtilizatoriRepository ur = new UtilizatoriRepository(null, Session["conStr"].ToString());

            try
            {
                FormsAuthentication.SignOut();
            }
            catch { }

            if (Convert.ToBoolean(ConfigurationManager.AppSettings["UseDoubleAutentificationForLogin"]))
            {
                if (TempData["tempLogin"] == null)
                {
                    response r = ur.Login(model.Username, model.Password);
                    if (r.Result != null)
                    {
                        TempData["tempLogin"] = (Utilizator)r.Result;
                        string _to = ((Utilizator)r.Result).EMAIL;
                        //string rnd = "1234"; // pt. test

                        Random generator = new Random();
                        string rnd       = generator.Next(0, 1000000).ToString("D6");
                        SendVerificationCode(EmailProfiles.AwsCereriSES, _to, rnd);

                        TempData["verificationCode"]          = rnd;
                        TempData["verificationCodeIssueTime"] = DateTime.Now;
                        return(RedirectToAction("Login", "Utilizatori", new { returnUrl = returnUrl }));
                    }
                    else
                    {
                        ModelState.AddModelError("", socisaV2.Resources.ErrorMessagesResx.FAILED_LOGIN);
                        return(View(model));
                    }
                }
                else
                {
                    if (TempData["verificationCode"] == null || String.IsNullOrWhiteSpace(TempData["verificationCode"].ToString())) // a expirat codul! TO DO !!!
                    {
                        ModelState.AddModelError("", socisaV2.Resources.ErrorMessagesResx.VERIFICATION_CODE_EXPIRED);
                        //TempData.Clear();
                        TempData.Keep();
                        return(View(model));
                        //return RedirectToAction("Login", "Utilizatori", new { returnUrl = returnUrl });
                    }
                    else
                    {
                        var passedSeconds = (DateTime.Now - (DateTime)TempData["verificationCodeIssueTime"]).TotalSeconds;
                        if (Math.Abs((int)passedSeconds) > Convert.ToInt32(ConfigurationManager.AppSettings["VerificationCodeExpiration"]))
                        {
                            ModelState.AddModelError("", socisaV2.Resources.ErrorMessagesResx.VERIFICATION_CODE_EXPIRED);
                            //TempData.Clear();
                            TempData.Keep();
                            return(View(model));
                            //return RedirectToAction("Login", "Utilizatori", new { returnUrl = returnUrl });
                        }
                        else
                        {
                            if (String.IsNullOrEmpty(model.Code))
                            {
                                ModelState.AddModelError("", socisaV2.Resources.ErrorMessagesResx.EMPTY_CODE);
                                return(View(model));
                            }
                            else
                            {
                                if (model.Code != TempData["verificationCode"].ToString())
                                {
                                    ModelState.AddModelError("", socisaV2.Resources.ErrorMessagesResx.VERIFICATION_CODE_DONT_MATCH);
                                    return(View(model));
                                }
                                else
                                {
                                    return(LoginInternal(returnUrl));
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                response r = ur.Login(model.Username, model.Password);
                if (r.Result != null)
                {
                    TempData["tempLogin"] = (Utilizator)r.Result;
                    return(LoginInternal(returnUrl));
                }
                else
                {
                    ModelState.AddModelError("", socisaV2.Resources.ErrorMessagesResx.FAILED_LOGIN);
                    return(View(model));
                }
            }
        }