Ejemplo n.º 1
0
        public JsonResult ChangePassword(UserViewModel model)
        {
            var result = 0;

            try
            {
                //Пользователь меняет свой пароль - проверяем ввод старого пароля
                if (model.user_id == Convert.ToInt32(Session["userID"]))
                {
                    Users Use = db.Users.SingleOrDefault(x => x.user_id == model.user_id);
                    if (Use.user_password != encryption(model.user_password_old))
                    {
                        result = 1;
                        return(Json(result, JsonRequestBehavior.AllowGet));
                    }
                }

                if ((model.user_id > 0) && (model.user_password != null) && (model.user_password.Trim() != ""))
                {
                    Users Use = db.Users.SingleOrDefault(x => x.user_id == model.user_id);
                    Use.user_password = encryption(model.user_password);
                    db.SaveChanges();
                }
                else
                {
                    result = 2;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public JsonResult ChangePassword(UserViewModel model)
        {
            var result = 0;

            try
            {
                using (ReportScheduleEntities db = new ReportScheduleEntities())
                {
                    Guid guid = Guid.Parse(Request.Form["guid"].ToString());

                    Reminded remind = db.Reminded.Where(x => x.remind_guid == guid).SingleOrDefault();

                    if ((remind.remind_user_id > 0) && (model.user_password != null) && (model.user_password.Trim() != ""))
                    {
                        Users Use = db.Users.SingleOrDefault(x => x.user_id == remind.remind_user_id);
                        Use.user_password = encryption(model.user_password);
                        db.SaveChanges();

                        db.Reminded.Remove(remind);
                        db.SaveChanges();
                    }
                    else
                    {
                        result = 1;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Register(LoginViewModel userModel)
        {
            try
            {
                using (ReportScheduleEntities db = new ReportScheduleEntities())
                {
                    if ((userModel.user_new_login == null) || (userModel.user_new_password.Trim() == "") || (userModel.user_confirm_password.Trim() == "") || (userModel.user_email.Trim() == ""))
                    {
                        ViewBag.Action = "Register";
                        return(View("Index", userModel));
                    }

                    if (CheckUserLogin(userModel.user_new_login.Trim(), userModel.user_id))
                    {
                        userModel.LoginErrorMessage = "Такой логин уже существует!";
                        ViewBag.Action = "Register";
                        return(View("Index", userModel));
                    }

                    if (CheckUserEmail(userModel.user_email.Trim(), userModel.user_id))
                    {
                        userModel.LoginErrorMessage = "Такой email уже существует!";
                        ViewBag.Action = "Register";
                        return(View("Index", userModel));
                    }

                    string pass = encryption(userModel.user_new_password);

                    Guid guid = Guid.NewGuid();

                    Registered reg = new Registered()
                    {
                        reg_email      = userModel.user_email.Trim(),
                        reg_login      = userModel.user_new_login.Trim(),
                        reg_surname    = userModel.user_surname,
                        reg_name       = userModel.user_name,
                        reg_patronymic = userModel.user_patronymic,
                        reg_password   = pass,
                        reg_guid       = guid
                    };

                    SendMail(reg.reg_email, guid.ToString());

                    db.Registered.Add(reg);
                    db.SaveChanges();

                    ViewBag.Action = "Registered";
                    return(View("Index", userModel));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult Forgot(LoginViewModel userModel)
        {
            try
            {
                using (ReportScheduleEntities db = new ReportScheduleEntities())
                {
                    if (userModel.user_email.Trim() == "")
                    {
                        ViewBag.Action = "Forgot";
                        return(View("Index", userModel));
                    }

                    if (!CheckUserEmail(userModel.user_email.Trim(), userModel.user_id))
                    {
                        userModel.LoginErrorMessage = "Такой email в системе не зарегистрирован!";
                        ViewBag.Action = "Forgot";
                        return(View("Index", userModel));
                    }

                    Users user = db.Users.Where(x => x.user_email == userModel.user_email.Trim()).SingleOrDefault();

                    Guid guid = Guid.NewGuid();

                    Reminded remind = new Reminded()
                    {
                        remind_guid    = guid,
                        remind_user_id = user.user_id
                    };

                    SendMailForgot(user.user_id, user.user_email, guid.ToString());

                    db.Reminded.Add(remind);
                    db.SaveChanges();

                    ViewBag.Action = "Forgoted";
                    return(View("Index", userModel));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 5
0
        public JsonResult AddWish()
        {
            var result = 0;

            try
            {
                //Вытаскиваем данные из запроса
                int               report_type_id   = Convert.ToInt32(Request.Form["report_type_id"]);
                int               user_id          = Convert.ToInt32(Request.Form["user_id"]);
                string            report_type_name = db.Report_types.Where(x => x.report_type_id == report_type_id).SingleOrDefault().report_type_name;
                DateTime          deadlineValue    = DateTime.ParseExact(Request.Form["deadlineValue"].ToString(), "yyyy-MM-ddTHH:mm", System.Globalization.CultureInfo.InvariantCulture);
                int?              attemptsCount    = Request.Form["attemptsCount"].ToString() != "null" ? Convert.ToInt32(Request.Form["attemptsCount"].ToString()) : (int?)null;
                List <parameters> ParamList        = JsonConvert.DeserializeObject <List <parameters> >(Request.Form["parameters"].ToString());
                List <places>     PlaceList        = JsonConvert.DeserializeObject <List <places> >(Request.Form["places"].ToString());

                //Доступы к просмотру
                int[] Access_users = Array.ConvertAll(Request.Form.GetValues("access_user"), s => int.Parse(s));

                string wish_report_type_xml = String.Empty;

                string report_type_xml = db.Report_types.Where(x => x.report_type_id == report_type_id).SingleOrDefault().report_type_xml ?? "";

                List <ParameterType> ParameterList = new List <ParameterType>();

                if (!String.IsNullOrEmpty(report_type_xml))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(ReportModel));

                    using (TextReader reader = new StringReader(report_type_xml))
                    {
                        ReportModel report = (ReportModel)serializer.Deserialize(reader);

                        foreach (var p in report.Parameters)
                        {
                            ParameterList.Add(new ParameterType
                            {
                                Name  = p.ParameterName,
                                Alias = p.ParameterAlias,
                                Type  = p.ParameterDataType,
                                Value =
                                    (p.ParameterDataType == "startdate") || (p.ParameterDataType == "enddate")
                                    ? DateTime.ParseExact(ParamList.Where(x => x.name == p.ParameterName).SingleOrDefault().value, "yyyy-MM-ddTHH:mm", System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy-MM-dd HH:mm:ss")
                                    : ParamList.Where(x => x.name == p.ParameterName).SingleOrDefault().value
                            });
                        }

                        wish_report_type_xml  = "<?xml version=\"1.0\" encoding=\"utf-16\"?>";
                        wish_report_type_xml += "<TableDataSource SelectCommand=\"" + SecurityElement.Escape(report.SelectCommand) + "\">";
                        foreach (var c in report.Columns)
                        {
                            wish_report_type_xml += "<Column Name=\"" + c.ColumnName + "\" Type=\"" + c.ColumnType + "\" Alias=\"" + c.ColumnAlias + "\" />";
                        }
                        if (ParamList.Count != 0)
                        {
                            foreach (var p in ParameterList)
                            {
                                wish_report_type_xml += "<CommandParameter Name=\"" + p.Name + "\" Alias=\"" + p.Alias + "\" DataType=\"" + p.Type + "\" Value=\"" + p.Value + "\" />";
                            }
                        }
                        wish_report_type_xml += "</TableDataSource>";
                    }
                }
                else
                {
                    result = 1;
                }

                //Создаем задание
                Wishes Wish = new Wishes();
                Wish.wish_createdate       = Convert.ToDateTime(DateTime.Now);
                Wish.wish_deadline         = deadlineValue;
                Wish.wish_total_attempts   = attemptsCount;
                Wish.wish_report_type_name = report_type_name;
                Wish.wish_status           = "not_ready";
                Wish.wish_report_type_xml  = wish_report_type_xml;
                Wish.wish_user_id          = user_id;
                db.Wishes.Add(Wish);
                db.SaveChanges();

                //Создаем задачи
                foreach (var p in PlaceList)
                {
                    Tasks Task = new Tasks();
                    Task.task_startdate       = DateTime.ParseExact(p.startdate, "yyyy-MM-ddTHH:mm", System.Globalization.CultureInfo.InvariantCulture);
                    Task.task_wish_id         = Wish.wish_id;
                    Task.task_place_id        = p.id;
                    Task.task_number_attempts = 0;
                    Task.task_status          = "new";
                    Task.task_last_error_text = null;
                    db.Tasks.Add(Task);
                }

                //Создаем доступы
                if (Access_users.Length != 0)
                {
                    Wish_report_relation wrr = new Wish_report_relation();
                    wrr.wrr_wish_id        = Wish.wish_id;
                    wrr.wrr_report_type_id = report_type_id;
                    wrr.wrr_access_type    = (short)((Access_users[0] == -1) ? 1 : (Access_users[0] == 0) ? 0 : 2);
                    db.Wish_report_relation.Add(wrr);
                    db.SaveChanges();

                    //Конкретные пользователи
                    if (wrr.wrr_access_type == 2)
                    {
                        foreach (int item in Access_users)
                        {
                            Wish_user_relation wur = new Wish_user_relation();
                            wur.wur_wish_id = Wish.wish_id;
                            wur.wur_user_id = item;
                            db.Wish_user_relation.Add(wur);
                        }
                        db.SaveChanges();
                    }
                }
                //Доступ для всех
                else
                {
                    Wish_report_relation wrr = new Wish_report_relation();
                    wrr.wrr_wish_id        = Wish.wish_id;
                    wrr.wrr_report_type_id = report_type_id;
                    wrr.wrr_access_type    = 0;
                    db.Wish_report_relation.Add(wrr);
                    db.SaveChanges();
                }

                Wish.wish_status = "new";
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
        public JsonResult SetAccess()
        {
            int result = 0;

            try
            {
                //Доступы к просмотру
                int[] Access_users = Array.ConvertAll(Request.Form.GetValues("access_user"), s => int.Parse(s));
                int   wish_id      = Convert.ToInt32(Request.Form["wish_id"]);
                int   access_type  = Convert.ToInt32(Request.Form["access_type"]);

                Wish_report_relation wrr = db.Wish_report_relation.Where(x => x.wrr_wish_id == wish_id).SingleOrDefault();

                if (wrr == null)
                {
                    result = 1;
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                wrr.wrr_access_type = (short)access_type;

                //Выбранные пользователи
                if (access_type == 2)
                {
                    List <Wish_user_relation> Wur = new List <Wish_user_relation>();

                    foreach (Wish_user_relation wur in db.Wish_user_relation.Where(x => x.wur_wish_id == wish_id))
                    {
                        Wur.Add(wur);
                    }

                    foreach (Users user in db.Users)
                    {
                        if (Access_users.Contains(user.user_id))
                        {
                            if (Wur.Find(x => x.wur_user_id == user.user_id) == null)
                            {
                                db.Wish_user_relation.Add(new Wish_user_relation()
                                {
                                    wur_user_id = user.user_id, wur_wish_id = wish_id
                                });
                            }
                        }
                        else
                        {
                            if (Wur.Find(x => x.wur_user_id == user.user_id) != null)
                            {
                                db.Wish_user_relation.Remove(Wur.Find(x => x.wur_user_id == user.user_id));
                            }
                        }
                    }
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveReport()
        {
            var result = 0;

            try
            {
                //Вытаскиваем данные из запроса
                int?       report_type_id = Convert.ToInt32(Request.Form["search_report_type_id"]);
                List <int> GroupList      = Request.Form["search_groups"].Split(',').Select(Int32.Parse).ToList();
                List <int> PlaceList      = Request.Form["search_places"].Split(',').Select(Int32.Parse).ToList();
                List <int> UserList       = Request.Form["search_users"].Split(',').Select(Int32.Parse).ToList();

                if ((report_type_id == null) || (report_type_id == 0))
                {
                    result = 1;
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                //Отчет-группы ДО редактирования
                List <Report_group_relation> Rgr = new List <Report_group_relation>();
                foreach (Report_group_relation rgr in db.Report_group_relation.Where(x => x.rgr_report_id == report_type_id))
                {
                    Rgr.Add(rgr);
                }

                foreach (Report_groups rg in db.Report_groups)
                {
                    if (GroupList.Contains(rg.report_group_id))
                    {
                        if (Rgr.Find(x => x.rgr_report_group_id == rg.report_group_id) == null)
                        {
                            db.Report_group_relation.Add(new Report_group_relation()
                            {
                                rgr_report_id = (int)report_type_id, rgr_report_group_id = rg.report_group_id
                            });
                        }
                    }
                    else
                    {
                        if (Rgr.Find(x => x.rgr_report_group_id == rg.report_group_id) != null)
                        {
                            db.Report_group_relation.Remove(Rgr.Find(x => x.rgr_report_group_id == rg.report_group_id));
                        }
                    }
                }

                //Отчет-места ДО редактирования
                List <Report_place_relation> Rpr = new List <Report_place_relation>();
                foreach (Report_place_relation rpr in db.Report_place_relation.Where(x => x.rpr_report_type_id == report_type_id))
                {
                    Rpr.Add(rpr);
                }

                foreach (Places p in db.Places)
                {
                    if (PlaceList.Contains(p.place_id))
                    {
                        if (Rpr.Find(x => x.rpr_place_id == p.place_id) == null)
                        {
                            db.Report_place_relation.Add(new Report_place_relation()
                            {
                                rpr_report_type_id = (int)report_type_id, rpr_place_id = p.place_id
                            });
                        }
                    }
                    else
                    {
                        if (Rpr.Find(x => x.rpr_place_id == p.place_id) != null)
                        {
                            db.Report_place_relation.Remove(Rpr.Find(x => x.rpr_place_id == p.place_id));
                        }
                    }
                }

                //Отчет-пользователи ДО редактирования
                List <Report_user_relation> Rur = new List <Report_user_relation>();
                foreach (Report_user_relation rur in db.Report_user_relation.Where(x => x.rur_report_type_id == report_type_id))
                {
                    Rur.Add(rur);
                }

                foreach (Users u in db.Users)
                {
                    if (UserList.Contains(u.user_id))
                    {
                        if (Rur.Find(x => x.rur_user_id == u.user_id) == null)
                        {
                            db.Report_user_relation.Add(new Report_user_relation()
                            {
                                rur_report_type_id = (int)report_type_id, rur_user_id = u.user_id
                            });
                        }
                    }
                    else
                    {
                        if (Rur.Find(x => x.rur_user_id == u.user_id) != null)
                        {
                            db.Report_user_relation.Remove(Rur.Find(x => x.rur_user_id == u.user_id));
                        }
                    }
                }

                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Activate(string user_guid)
        {
            try
            {
                using (ReportScheduleEntities db = new ReportScheduleEntities())
                {
                    Guid guid = Guid.Parse(user_guid);

                    Registered reg = db.Registered.Where(x => x.reg_guid == guid).SingleOrDefault();

                    if (reg == null)
                    {
                        ViewBag.Action = "Не найдено в таблице запроса на регистрацию. Возможно вы уже зарегистрированы.";
                        return(View("Index", null));
                    }

                    if (CheckUserLogin(reg.reg_login, 0))
                    {
                        ViewBag.Action = "Пользователь под таким логином уже был зарегистрирован.";
                        return(View("Index", null));
                    }

                    if (CheckUserEmail(reg.reg_email, 0))
                    {
                        ViewBag.Action = "Пользователь с таким email уже был зарегистрирован.";
                        return(View("Index", null));
                    }

                    Users user = new Users()
                    {
                        user_email      = reg.reg_email,
                        user_isdeleted  = false,
                        user_login      = reg.reg_login,
                        user_password   = reg.reg_password,
                        user_surname    = reg.reg_surname,
                        user_name       = reg.reg_name,
                        user_patronymic = reg.reg_patronymic
                    };

                    db.Users.Add(user);
                    db.SaveChanges();

                    User_roles userrole = new User_roles()
                    {
                        userrole_user_id = user.user_id,
                        userrole_role_id = 4
                    };

                    db.User_roles.Add(userrole);
                    db.SaveChanges();

                    db.Registered.Remove(reg);
                    db.SaveChanges();

                    List <int> userRoles = db.User_roles.Where(x => x.userrole_user_id == user.user_id).Select(x => x.userrole_role_id).ToList();

                    Session["userID"]      = user.user_id;
                    Session["userSurname"] = user.user_surname;
                    Session["userName"]    = user.user_name;
                    Session["userRoles"]   = userRoles;
                }

                ViewBag.Action = "Login";

                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }