コード例 #1
0
 public ActionResult Register(){
     if (Request.IsAuthenticated) {
         user = GetUser();
         return RedirectUrl("/member/u-"+user.Id+"/show");
     }
     return View();
 }
コード例 #2
0
 public JsonResult MultiDel(string[] chk)
 {
     if (chk.Length == 0) {
         hitStr = "未选中行,请选中行后再进行操作!";
     }
     else
     {
         using (club = new ClubEntities())
         {
             foreach (string ck in chk)
             {
                 tId = Convert.ToInt32(ck);
                 user = club.Users.Where(b => b.Id == tId).FirstOrDefault();
                 club.Users.Remove(user);
             }
             if (club.SaveChanges() >= 0)
             {
                 hitStr = "账号删除成功!";
                 status = Status.success;
             }
             else
             {
                 hitStr = "系统异常删除失败,请稍后重试!";
             }
         }
     }
     return Json(new { state = status.ToString(), context = hitStr.ToString(), url = "/bwum/users/" });
 }
コード例 #3
0
 public ActionResult Login(string username, string password, string returnurl) {
     if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { 
             ViewBag.Status = "<span style=\"color:red\">用户名或密码不能为空!</span>";
     }
     BaWuClub.Web.Dal.User user = new User() { NickName=HtmlCommon.ClearHtml(username),Password= System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5")};
     using (club = new ClubEntities()) {
         var _user = club.Users.Where(u =>u.NickName ==user.NickName  && u.Password ==user.Password).FirstOrDefault();
         if (_user!=null){
             if (_user.LastLoginDate < DateTime.Now) {
                 _user.Points += 2;
             }
             _user.LastLoginDate = DateTime.Now;
             _user.LastLoginIP = Request.UserHostAddress;
             club.SaveChanges();
             //System.Web.Security.FormsAuthentication.SetAuthCookie(user.NickName, true);
             //HttpCookie cookie = new HttpCookie("bwusers");
             //cookie.Values["id"] = _user.Id.ToString();
             //cookie.Values["user"] = HttpUtility.UrlEncode(_user.NickName.ToString());
             //cookie.Values["avatar"] = _user.Cover;
             Response.Cookies.Add(SetCookies(_user));
             return RedirectUrl(returnurl);
         }
         else { 
             ViewBag.Status = "<span style=\"color:red\">用户名或密码不正确!</span>";}
     }
     return View();
 }
コード例 #4
0
 public ActionResult Show(int? id) {
     BaWuClub.Web.Dal.User user = new User() { Id=Convert.ToInt32(id)};
     using (club = new ClubEntities()) {
         user = club.Users.Single<BaWuClub.Web.Dal.User>(u => u.Id == user.Id);
     }
     return View(user);
 }
コード例 #5
0
        public JsonResult MassSend(string ids, string context) {
            user=GetUser();
            ids=HtmlCommon.ClearHtml(ids);
            context=HtmlCommon.ClearHtml(context);
            if (string.IsNullOrEmpty(ids)){
                hintStr = "信息发送失败,没有选择用户!";
            }
            else {

                if (string.IsNullOrEmpty(context)){
                    hintStr = "信息发送失败,发送的信息不能空!";
                }
                else {
                    string[] idArray = ids.Split(',');
                    int[] idIntArray = new int[idArray.Length];
                    int value = 0;
                    for (int i = 0; i < idArray.Length; i++){
                        Int32.TryParse(idArray[i],out value);
                        idIntArray[i] = value;
                    }
                    using (club = new ClubEntities())
                    {
                        List<Message> Messages=new List<Message>();
                        foreach (int item in idIntArray) {
                            var msg = new Message() {FromId=user.Id,ToId=item,Message1=context,Status=(byte)State.Disable, Ip=Request.UserHostAddress,Vardate=DateTime.Now,Title="个人消息" };
                            club.Messages.Add(msg);
                        }
                        if (club.SaveChanges() >= 0) {
                            status = Status.success;
                            hintStr = "发送成功!";
                        }else{
                            hintStr = "系统异常!!";
                        }
                    }
                }
            }
            return Json(new {status=status.ToString(),context=hintStr });
        }
コード例 #6
0
 public JsonResult Vote(int qid,int aid,string vt) {
     Answer answer = new Answer();
     bool isCancel = false;
     int pro=0,con = 0;
     user = GetUser();
     if (user != null) { 
         using (club = new ClubEntities()) {
             answer = club.Answers.Where(a => a.Id == aid).FirstOrDefault();
             if (answer == null) {
                 context = "该问题不存在!";
             }
             else{
                 answerVote = club.AnswerVotes.Where(av => av.AId == aid && av.QId == qid && av.UId == user.Id).FirstOrDefault();
                 if (vt.Equals("up")) {
                     if (answerVote == null) {
                         club.AnswerVotes.Add(CreateVote(aid,qid,user.Id,1));
                         answer.Agree = answer.Agree + 1;
                     }
                     else {
                         if (answerVote.Vote == 0) {
                             answerVote.Vote = 1;
                             answer.Oppose = (answer.Oppose - 1) > 0 ? (answer.Oppose - 1) : 0;
                             answer.Agree = answer.Agree + 1;
                         }
                         else {
                             club.AnswerVotes.Remove(answerVote);
                             answer.Agree = (answer.Agree - 1) > 0 ? (answer.Agree - 1) : 0;
                             isCancel = true;
                         }
                     }
                 }
                 if (vt.Equals("down")) {
                     if (answerVote == null) {
                         club.AnswerVotes.Add(CreateVote(aid,qid,user.Id,0));
                         answer.Oppose = answer.Oppose + 1;
                     }
                     else {
                         if (answerVote.Vote == 1) {
                             answerVote.Vote = 0;
                             answer.Agree = (answer.Agree - 1) > 0 ? (answer.Agree - 1) : 0;
                             answer.Oppose = answer.Oppose + 1;
                         }
                         else {
                             club.AnswerVotes.Remove(answerVote);
                             answer.Oppose = (answer.Oppose - 1) > 0 ? (answer.Oppose - 1) : 0;
                             isCancel = true;
                         }
                     }
                 }
                 if(club.SaveChanges()>=0){
                     status=Status.success;
                     context="操作成功!";
                 }
                 pro = answer.Agree;
                 con = answer.Oppose;
             }
         }
     }
     else {
         return Json(new {status=Status.warning.ToString(),url="/account/login?returnurl=/ask/show/"+qid },JsonRequestBehavior.AllowGet);
     }
     return Json(new { status = status.ToString(), context = context,iscancel=isCancel,pro=pro,con=con,op=vt }, JsonRequestBehavior.AllowGet);
 }
コード例 #7
0
 public JsonResult AnswerQuestions(int id,string commentStr) {
     user = GetUser();
     Answer answer = new Answer();
     StringBuilder str = new StringBuilder();
     if (user == null || !User.Identity.IsAuthenticated)
         return Json(new {status=Status.warning.ToString(),url="/account/login?returnurl=/ask/show/"+id });
     using (club = new ClubEntities()) {
         answer.UserId = user.Id;
         answer.QId = id;
         answer.Answer1 = HtmlCommon.ClearJavascript(commentStr);
         answer.VarDate = DateTime.Now;
         answer.IP = Request.UserHostAddress;
         club.Answers.Add(answer);
         if (club.SaveChanges() >= 0) {
             status = Status.success;
             str.Append("<div class=\"comment-item\">");
             str.Append("<div class=\"comment-item-info\">");
             str.Append("<a href=\"/member/u-" + user.Id + "/show/\" class=\"comment-item-info-name\">" + user.NickName + "</a>");
             str.Append("<a href=\"/member/u-" + user.Id + "/show/\" class=\"comment-item-info-avatar\"><img src=\""+(string.IsNullOrEmpty(user.Cover)?"/content/images/no-img.jpg":"/uploads/avatar/small/"+user.Cover)+"\"/>");
             str.Append("</a>");
             str.Append("</div>");
             str.Append("<div class=\"comment-item-content\">"+HtmlCommon.ClearJavascript(commentStr)+"</div>");
             str.Append("<div class=\"comment-item-meta\"><span>评论与"+HtmlCommon.GetAnswerTimeSpan(answer.VarDate)+"</span></div>");
             str.Append("</div>");
         }
     }
     return Json(new { status = status.ToString(), context = str.ToString() });
 }
コード例 #8
0
 private bool UserReg(BaWuClub.Web.Dal.User user,ClubEntities c) {
     this.user = user;
     c.Users.Add(user);
     if(c.SaveChanges()<0)
         return false;
     return true;
 }
コード例 #9
0
 private BaWuClub.Web.Dal.User CreateUser(string username,string password,string email,string tid,int type) {
     var u = new User
     {
         NickName = HtmlCommon.ClearHtml(username),
         Password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5"),
         Email = HtmlCommon.ClearHtml(email),
         RegDate = DateTime.Now,
         LastLoginDate = DateTime.Now,
         LastLoginIP = Request.UserHostAddress,
         Tid = HtmlCommon.ClearHtml(tid),
         Type = (byte)type,
         Status = 1,
         Membership = 0,
         Points = 0,
         Cover = ""
     };
     return u;
 }
コード例 #10
0
 public ActionResult ThirdLogin(string tid,string nickname) {
      using (club = new ClubEntities()){
          user = club.Users.Where(u => u.Tid == tid).FirstOrDefault();
          Response.Cookies.Add(SetCookies(user));
          if (user != null) {
              user.LastLoginDate = DateTime.Now;
              user.LastLoginIP = Request.UserHostAddress;
              club.SaveChanges();
          }
      }
      return Redirect("/home");
 }
コード例 #11
0
       public ActionResult ThirdReg(string tid,string nickname) {
           if(string.IsNullOrEmpty(tid)){
               ViewBag.hint = "账号未授权,请<a href=\"/account/qqoauth\">点此</a>重新授权!";
               return View("~/views/account/thirdaccount.cshtml");
           }
           else if(string.IsNullOrEmpty(nickname)){
               ViewBag.hint = "还是给您自己起个霸气的名字吧!";
               return View("~/views/account/thirdaccount.cshtml");
           }
           else if (CheckName(nickname,null)){
               ViewBag.hint = "改名字已存在了,换个吧!";
               return View("~/views/account/thirdaccount.cshtml");
           }
           else {
               bool flag=false;
               if (!ThirdUserExist(tid)) {
                   using (club = new ClubEntities()) {
                       user = CreateUser(nickname, "", "", tid, 1);
                       if (UserReg(user,club)){
                           flag = true;
                           Response.Cookies.Add(SetCookies(user));
                       }

                   }
               }
               if (flag) { 
                   Session.Clear();
                   return Redirect("/home");
               }
               else { 
                ViewBag.hint = "登录账号失败,请稍后重试!";
                return View("~/views/account/thirdaccount.cshtml");
              }
           }
       }
コード例 #12
0
 private bool SetStatus(string[] chks, int sId)
 {
     using (club = new ClubEntities())
     {
         user = new User();
         foreach (string chk in chks)
         {
             tId = Convert.ToInt32(chk);
             user = club.Users.Where(a => a.Id == tId).FirstOrDefault();
             user.Status = (byte)sId;
             if (club.SaveChanges() < 0)
                 return false;
         }
         return true;
     }
 }
コード例 #13
0
 private void DelUser(int id)
 {
     using (club = new ClubEntities()){
         BaWuClub.Web.Dal.User user = new Dal.User();
         user = club.Users.Where(u => u.Id == id).FirstOrDefault();
         if (user != null) {
             club.Users.Remove(user);
         }
         if (club.SaveChanges() > 0)
             ViewBag.StatusStr = "删除成功!";
         else
             ViewBag.StatusStr = "删除失败,请稍后重试";
     }
 }