示例#1
0
        public ActionResult FindPassword(FormCollection form)
        {
            ViewBag.ok = false;
            var email = form["email"].Trim();

            using (var db = new RIPPWebEntities())
            {
                var has_member = db.S_User.FirstOrDefault(d => d.Email == email && !d.Deleted);
                if (has_member == null)
                {
                    ViewBag.Msg = "该Email还未注册";
                    return(View());
                }
                string guid   = Guid.NewGuid().ToString();
                string secret = Common.GetRnd(4, true, true, true);
                db.S_FindPWD.Add(new S_FindPWD()
                {
                    uid        = has_member.ID,
                    Email      = has_member.Email,
                    Secret     = secret,
                    Guid       = guid,
                    SubmitDate = DateTime.Now
                });
                db.SaveChanges();
                Common.SendEmail(has_member.Email, has_member.RealName, guid, secret);
                ViewBag.ok  = true;
                ViewBag.Msg = "重置密码的邮件已发送到" + has_member.Email + ",请尽快重置密码!";
            }
            return(View());
        }
示例#2
0
 public ActionResult Signup(RegisterModel model)
 {
     using (var db = new RIPPWebEntities())
     {
         // Attempt to register the user
         MembershipCreateStatus createStatus = MembershipCreateStatus.Success;
         db.S_User.Add(new S_User()
         {
             RealName      = model.RealName.Trim(),
             PhoneCell     = model.CellPhone.Trim(),
             Email         = model.Email.Trim(),
             GroupID       = model.GroupID,
             Pwd           = Common.MD5_Pass(model.Password),
             LastLoginTime = DateTime.Now,
             AddTime       = DateTime.Now
         });
         db.SaveChanges();
         if (createStatus == MembershipCreateStatus.Success)
         {
             return(RedirectToAction("Waite", "Account"));
         }
         else
         {
             ModelState.AddModelError("", ErrorCodeToString(createStatus));
         }
     }
     // If we got this far, something failed, redisplay form
     return(View(model));
 }
示例#3
0
        public ActionResult Predict(int modelid, string specid)
        {
            ViewBag.Title = "预测结果";
            ViewBag.Nav   = new Models.LeftNavEntity()
            {
                Panel = Models.LeftNavPanel.User
            };



            if (string.IsNullOrWhiteSpace(specid))
            {
                return(View());
            }
            using (var db = new RIPPWebEntities())
            {
                var model = db.model.Where(d => d.id == modelid).FirstOrDefault();
                if (model == null)
                {
                    return(View());
                }
                //查询未被预测过的光谱
                string sql           = string.Format("select * from spec where id not in ( select sid from results where mid={0} and sid in ({1}) )", modelid, specid);
                var    noResultSpecs = db.Database.SqlQuery <spec>(sql).ToList();
                foreach (var s in noResultSpecs)
                {
                    ComponentList c;
                    var           r = model.Predict(s, out c);
                    db.results.Add(new results()
                    {
                        addtime  = DateTime.Now,
                        mid      = modelid,
                        sid      = s.id,
                        uid      = RIPP.Web.Chem.Tools.Common.Get_UserID,
                        contents = Serialize.ObjectToByte(r),
                        componts = c != null ? Serialize.ObjectToByte(c) : null
                    });
                }
                db.SaveChanges();
                sql = string.Format("select * from results where mid={0} and sid in ({1})", modelid, specid);
                return(View(db.Database.SqlQuery <results>(sql).ToList()));
            }
        }
示例#4
0
        public ActionResult Delete(int id)
        {
            if (!Common.IsLogin)
            {
                return(new HttpUnauthorizedResult());
            }


            using (var db = new RIPPWebEntities())
            {
                var item = db.S_User.Where(d => d.ID == id && !d.Deleted).FirstOrDefault();
                if (item != null)
                {
                    item.Deleted = true;

                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
        }
示例#5
0
        public ActionResult ResetPass(FormCollection form)
        {
            string newpwd = form["password"].Trim();
            int    uid    = int.Parse(Session["EmailBackID"].ToString());

            using (var db = new RIPPWebEntities())
            {
                var changeUser = db.S_User.FirstOrDefault(d => d.ID == uid && !d.Deleted);
                changeUser.Pwd = Common.MD5_Pass(newpwd);
                var userSubmits = db.S_FindPWD.Where(d => d.uid == uid);
                foreach (var temp in userSubmits)
                {
                    db.S_FindPWD.Remove(temp);//找回密码后删除
                }
                db.SaveChanges();
                ViewBag.allowChange = false;
                ViewBag.Msg         = "您的密码已重置,请重新<a href=\"/Account/signin\">登录</a>。";
                return(View());
            }
        }
示例#6
0
        public ActionResult Enable(int id)
        {
            ViewBag.Nav = new Models.LeftNavEntity()
            {
                Panel = Models.LeftNavPanel.User
            };
            if (!Common.IsLogin)
            {
                return(new HttpUnauthorizedResult());
            }


            using (var db = new RIPPWebEntities())
            {
                var item = db.S_User.Where(d => d.ID == id && !d.Deleted).FirstOrDefault();
                if (item != null)
                {
                    item.Deleted = false;
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
        }
示例#7
0
        private FilesStatus upload(Stream inputStream, string fileName, HttpContext context)
        {
            var statu = new FilesStatus();

            var filename     = RIPP.Web.Chem.Tools.Common.GetRnd(10, true, true, false) + Path.GetExtension(fileName);
            var tempfullName = Path.Combine(StorageRoot, filename);

            statu.progress = "1.0";
            statu.size     = (int)inputStream.Length;
            statu.name     = fileName;
            try
            {
                //先保存在服务器一个临时文件
                using (var fs = new FileStream(tempfullName, FileMode.Append, FileAccess.Write))
                {
                    var buffer = new byte[1024];
                    var l      = inputStream.Read(buffer, 0, 1024);
                    while (l > 0)
                    {
                        fs.Write(buffer, 0, l);
                        l = inputStream.Read(buffer, 0, 1024);
                    }
                    fs.Flush();
                    fs.Close();
                }
            }
            catch
            {
                statu.error = "服务器错误,上传文件失败!";
                return(statu);
            }

            //根据文件后缀尝试打开文件
            var   ftype   = BindModel.CheckType(tempfullName);
            model dbmodel = new model();
            spec  sp      = new spec();

            try
            {
                statu.type   = ftype.GetDescription();
                dbmodel.path = Path.Combine(RIPP.Web.Chem.Tools.Common.GetUploadPath(), filename);
                sp.path      = dbmodel.path;
                switch (ftype)
                {
                case FileExtensionEnum.Allmethods:
                    var mBind = BindModel.ReadModel <BindModel>(tempfullName);
                    statu.description  = mBind.ToString();
                    dbmodel.createtime = mBind.CreateTime;
                    dbmodel.name       = mBind.Name;
                    // ;
                    // dbmodel.type = (int)ftype;
                    //  dbmodel.
                    break;

                case FileExtensionEnum.PLSBind:
                    var mPLS = BindModel.ReadModel <PLSModel>(tempfullName);
                    statu.description  = mPLS.ToString();
                    dbmodel.createtime = mPLS.CreateTime;
                    dbmodel.name       = mPLS.Name;
                    break;

                case FileExtensionEnum.IdLib:
                    var mId = BindModel.ReadModel <IdentifyModel>(tempfullName);
                    statu.description  = mId.ToString();
                    dbmodel.createtime = mId.CreateTime;
                    dbmodel.name       = mId.Name;
                    break;

                case FileExtensionEnum.FitLib:
                    var mFitting = BindModel.ReadModel <FittingModel>(tempfullName);
                    statu.description  = mFitting.ToString();
                    dbmodel.createtime = mFitting.CreateTime;
                    dbmodel.name       = mFitting.Name;
                    break;

                case FileExtensionEnum.PLS1:
                case FileExtensionEnum.PLSANN:
                    var mPLS1 = BindModel.ReadModel <PLSSubModel>(tempfullName);
                    statu.description  = mPLS1.ToString();
                    dbmodel.createtime = mPLS1.CreateTime;
                    dbmodel.name       = mPLS1.Name;
                    break;

                case FileExtensionEnum.ItgBind:
                    var itgSub = BindModel.ReadModel <IntegrateModel>(tempfullName);
                    statu.description  = itgSub.ToString();
                    dbmodel.createtime = itgSub.CreateTime;
                    dbmodel.name       = itgSub.Name;
                    break;

                case FileExtensionEnum.Spec:
                default:
                    var s = new Spectrum(tempfullName);
                    ftype             = FileExtensionEnum.Spec;
                    sp.Spec           = s;
                    sp.name           = Path.GetFileName(fileName);
                    statu.description = "光谱文件";
                    break;
                }
            }
            catch (Exception ex)//读取文件失败
            {
                statu.error = "上传的文件类型有误,服务器无法识别,上传文件失败!";

                if (File.Exists(tempfullName))
                {
                    File.Delete(tempfullName);
                }
                return(statu);
            }


            //根据文件类型保存数据库
            using (var db = new RIPPWebEntities())
            {
                if (ftype != FileExtensionEnum.Unkown)
                {
                    var user = RIPP.Web.Chem.Tools.Common.Get_User;
                    if (user == null)
                    {
                        var uid = Convert.ToInt32(context.Request["uid"]);
                        user = db.S_User.Where(d => d.ID == uid).FirstOrDefault();
                    }

                    if (ftype == FileExtensionEnum.Spec)//光谱
                    {
                        if (RIPP.Web.Chem.Tools.Common.UserCanPredict(user))
                        {
                            sp.addtime = DateTime.Now;
                            sp.ext     = Path.GetExtension(fileName).Substring(1);
                            sp.uid     = user.ID;
                            sp.gid     = user.GroupID;
                            db.spec.Add(sp);
                            db.SaveChanges();
                            statu.deleteType = "DELETE";
                            statu.deleteUrl  = "/upload/UploadHandler.ashx?t=s&id=" + sp.id;
                            statu.url        = "/admin/spec/detail/" + sp.id;
                            statu.id         = sp.id;

                            File.Move(tempfullName, Path.Combine(HttpContext.Current.Server.MapPath("~/"), sp.path));//移动刚才上传的临时文件
                        }
                        else
                        {
                            statu.error = "您无权上传光谱文件,请与管理员联系。";
                            if (File.Exists(tempfullName))
                            {
                                File.Delete(tempfullName);
                            }
                        }
                    }
                    else//模型
                    {
                        if (user.HasRole(RoleEnum.Administrator) || user.HasRole(RoleEnum.Engineer))
                        {
                            dbmodel.addtime = DateTime.Now;
                            dbmodel.type    = (int)ftype;
                            dbmodel.uid     = user.ID;
                            dbmodel.gid     = user.GroupID;
                            db.model.Add(dbmodel);
                            db.SaveChanges();
                            statu.deleteType = "DELETE";
                            statu.deleteUrl  = "/upload/UploadHandler.ashx?t=m&id=" + dbmodel.id;
                            statu.url        = "/admin/model/detail/" + dbmodel.id;
                            statu.id         = dbmodel.id;
                            File.Move(tempfullName, Path.Combine(HttpContext.Current.Server.MapPath("~/"), dbmodel.path));//移动刚才上传的临时文件
                        }
                        else
                        {
                            statu.error = "您无权上传模型文件,请与管理员联系。";
                            if (File.Exists(tempfullName))
                            {
                                File.Delete(tempfullName);
                            }
                        }
                    }
                }
            }

            return(statu);
        }
示例#8
0
        public ActionResult Edit(int id, S_User u, FormCollection form)
        {
            if (!Common.IsLogin)
            {
                return(new HttpUnauthorizedResult());
            }
            //RoleEnum role;

            //if (!Permission.Check(ModelEnum.Users, id > 0 ? PermissionEnum.Edit : PermissionEnum.Add, Common.Get_User.Roles, out role, Common.Get_UserID, id))
            //    return RedirectToAction("Forbid", "Home");

            if (!string.IsNullOrWhiteSpace(u.Pwd))
            {
                u.Pwd = Common.MD5_Pass(u.Pwd.Trim());
            }

            using (var db = new RIPPWebEntities())
            {
                var dbu = db.S_User.Where(d => d.ID == u.ID && !d.Deleted).FirstOrDefault();
                if (dbu != null)
                {
                    //if (u.ICID != dbu.ICID)//通知系统,用户卡被修改过,方便终端同步
                    //    Common.UserCardChanged();
                    dbu.Address    = u.Address;
                    dbu.ApplyState = u.ApplyState;
                    dbu.Email      = u.Email;

                    dbu.GroupID     = u.GroupID;
                    dbu.PhoneCell   = u.PhoneCell;
                    dbu.PhoneOffice = u.PhoneOffice;
                    if (!string.IsNullOrWhiteSpace(u.Pwd))
                    {
                        dbu.Pwd = u.Pwd;
                    }
                    dbu.RealName = u.RealName;
                    dbu.Remark   = u.Remark;
                }
                else
                {
                    if (db.S_User.Where(d => d.Email == u.Email && !d.Deleted).Count() > 0)
                    {
                        return(View("Info", new Models.InfoModel()
                        {
                            Icon = Models.InfoPage.highlight,
                            Info = "Email重复,请重新输入!"
                        }));
                    }
                    u.AddTime       = DateTime.Now;
                    u.LastLoginTime = DateTime.Now;
                    db.S_User.Add(u);
                }
                db.SaveChanges();



                //权限
                List <int> roleid = new List <int>();

                if (form.AllKeys.Contains(RoleEnum.Administrator.ToString()) && form[RoleEnum.Administrator.ToString()] == "1")
                {
                    roleid.Add((int)RoleEnum.Administrator);
                }
                if (form.AllKeys.Contains(RoleEnum.Engineer.ToString()) && form[RoleEnum.Engineer.ToString()] == "1")
                {
                    roleid.Add((int)RoleEnum.Engineer);
                }
                if (form.AllKeys.Contains(RoleEnum.GroupMaster.ToString()) && form[RoleEnum.GroupMaster.ToString()] == "1")
                {
                    roleid.Add((int)RoleEnum.GroupMaster);
                }
                if (form.AllKeys.Contains(RoleEnum.Operator.ToString()) && form[RoleEnum.Operator.ToString()] == "1")
                {
                    roleid.Add((int)RoleEnum.Operator);
                }


                var rlst = db.S_UserInRole.Where(r => r.UserID == u.ID);
                foreach (var r in rlst)
                {
                    db.S_UserInRole.Remove(r);
                }
                foreach (var i in roleid)
                {
                    db.S_UserInRole.Add(new S_UserInRole()
                    {
                        RoleID = i,
                        UserID = u.ID
                    });
                }
                db.SaveChanges();


                return(RedirectToAction("Index"));
            }
        }