示例#1
0
        public IActionResult UserLogin(myUser myUser)
        {
            if (ModelState.IsValid)
            {
                var userInDb = dbContext.Users.FirstOrDefault(u => u.Email == myUser.Email);
                if (userInDb == null)
                {
                    ModelState.AddModelError("myUser.Email", "Invalid Email or Password");
                    return(View("Index"));
                }

                var hasher = new PasswordHasher <myUser>();
                var result = hasher.VerifyHashedPassword(myUser, userInDb.Password, myUser.Password);

                if (result == 0)
                {
                    ModelState.AddModelError("myUser.Email", "Invalid Email or Password");
                    return(View("Index"));
                }
                HttpContext.Session.SetInt32("UserId", userInDb.UserId);
                HttpContext.Session.SetString("Username", userInDb.Username);

                return(RedirectToAction("BrightIdeas"));
            }
            return(View("Index"));
        }
示例#2
0
        public IActionResult UserLogin(myUser thisUser)
        {
            if(ModelState.IsValid)
            {
                var userInDb = dbContext.Users.FirstOrDefault(u => u.Email == thisUser.Email);
                if(userInDb == null)
                {
                    ModelState.AddModelError("Email", "Invalid Email or Password");
                    return View("Login");
                }

                var hasher = new PasswordHasher<myUser>();
                var result = hasher.VerifyHashedPassword(thisUser, userInDb.Password, thisUser.Password);

                if(result == 0)
                {
                    ModelState.AddModelError("Email", "Invalid Email or Password");
                    return View("Login");
                }

                HttpContext.Session.SetInt32("UserId", userInDb.UserId);
                HttpContext.Session.SetString("UserName", userInDb.FirstName);
                return RedirectToAction("success", new{id = userInDb.UserId});
            }
            return View("Login");
        }
示例#3
0
        public ActionResult Create([Bind(Include = "UserID,Name,Surname,Username,FK_TitleID,FK_GenderID,FK_RelationshipStatusIdn,FK_ActiveID,FK_CityID,LoginID, userLogin.UserPassword")] myUser myUser, string UserPassword)
        {
            userLogin ulogin     = new userLogin();
            var       hasedValue = ComputeSha256Hash(UserPassword);
            string    newHased   = hasedValue.Substring(0, 49);

            if (ModelState.IsValid)
            {
                userLogin ul = new userLogin();
                ul.UserPassword = newHased;
                ul.Username     = myUser.Username;
                ul.LoginType    = false;

                db.myUsers.Add(myUser);
                db.userLogins.Add(ul);
                db.SaveChanges();
                return(RedirectToAction("TopicSelect", "BaeCoach"));
            }

            ViewBag.FK_ActiveID = new SelectList(db.Actives, "ActiveID", "ActiveDescription", myUser.FK_ActiveID);
            ViewBag.FK_CityID   = new SelectList(db.Cities, "Id", "Name", myUser.FK_CityID);
            ViewBag.FK_GenderID = new SelectList(db.Genders, "GenderID", "GenderDescription", myUser.FK_GenderID);
            ViewBag.FK_RelationshipStatusIdn = new SelectList(db.RelationshipStatus, "RelationshipStatusID", "RelationshipStatusDescription", myUser.FK_RelationshipStatusIdn);
            ViewBag.FK_TitleID = new SelectList(db.Titles, "TitleID", "Titledescription", myUser.FK_TitleID);
            ViewBag.LoginID    = new SelectList(db.userLogins, "UserLoginID", "Username", myUser.LoginID);
            return(View(myUser));
        }
示例#4
0
    /// <summary>
    /// 增加或减少金币
    /// </summary>
    /// <param name="nubber">增加或减少的金币数量</param>
    /// <param name="beiZhu">这次操作的备注</param>
    public void updataJinBi(double nubber, string beiZhu)
    {
        user.jinBi += nubber;
        addCaoZuo(nubber, beiZhu, user.jinBi);

        //增加
        updataUser();
        return;

        BmobQuery queryUser = new BmobQuery();

        queryUser.WhereEqualTo("userId", user.userId);


        bmob.Find <myUser>(tableNameForUser, queryUser, (resp, exception) =>
        {
            if (exception != null)
            {
                showMessagem("查询异常" + exception.Message);
                return;
            }
            if (resp.results.Count == 0)
            {
                showMessagem("没有改用户  创建");
                creatUser();
            }

            else
            {
                showMessagem("查找到该用户" + resp.results[0]);
                user = resp.results[0];
            }
        });
    }
示例#5
0
    public static int deleteRecord(myUser obj)
    {
        string strSQL = "delete from myuser where userid='" + obj.username + "'";
        int    iRet   = DBOper.execNonQueryBySQLText(strSQL);

        return(iRet);
    }
示例#6
0
    public static int insertRecord(myUser obj)
    {
        string strSQL = "insert into myuser(username,userkey,userphone) values('" + obj.username + "','" + obj.userkey + "','" + obj.userphone + "')";
        int    iRet   = DBOper.execNonQueryBySQLText(strSQL);

        return(iRet);
    }
示例#7
0
        public string getProfilePhotoPath(myUser u)
        {
            string imagePath = "Content/data/images/defM.png";

            if (u.PhotoRef == null) //no photo added
            {
                if (u.Gender.Equals("F"))
                {
                    imagePath = "Content/data/images/defF.png";
                }
            }
            else
            {
                OfficeChatDBEntities context = new OfficeChatDBEntities();
                FileHolder           fh      = new FileHolder();
                fh        = context.FileHolders.Find(u.PhotoRef);
                imagePath = fh.FName;

                if (imagePath.ElementAt(0).Equals('~'))
                {
                    imagePath = imagePath.Substring(2);
                }
            }

            return(imagePath);
        }
示例#8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            OfficeChatDBEntities context = new OfficeChatDBEntities();
            int u1 = (int)Session["curUserID"];

            myUser user1 = context.myUsers.Find(u1);

            if (user1.Role != "manager")
            {
                wrapper.InnerHtml = "<h1>Managers only</h1> <a href='index.aspx'>Back to main page</a>";
            }
            else
            {
                Company c = context.Companies.Find(user1.Company);

                if (IsPostBack)
                {
                    string name  = String.Format("{0}", Request.Form["Text1"]);
                    string desc  = String.Format("{0}", Request.Form["Text2"]);
                    string email = String.Format("{0}", Request.Form["Text3"]);

                    c.N_ame = name;
                    c.D_esc = desc;
                    c.Email = email;

                    HttpPostedFile postedFile = Request.Files["FileUpload"];
                    if (postedFile != null && postedFile.ContentLength > 0)
                    {
                        string filePath = Server.MapPath("tmpFiles/") + Path.GetFileName(postedFile.FileName);

                        postedFile.SaveAs(filePath);


                        FileHolder fh = new FileHolder();
                        fh.FName = "~/tmpFiles/" + Path.GetFileName(postedFile.FileName);

                        context.FileHolders.Add(fh);
                        c.LogoRef = fh.FID;
                    }

                    user1.Company = c.CID;
                    context.SaveChanges();
                }
                else
                {
                    Text1.Value = c.N_ame;
                    Text2.Value = c.D_esc;
                    Text3.Value = c.Email;

                    Image img = new Image();
                    img.ImageUrl = getfilepathComp(c);
                    img.Height   = Unit.Pixel(100);
                    img.Width    = Unit.Pixel(100);

                    imageHere.Controls.Add(img);
                }
            }
        }
示例#9
0
        public ActionResult DeleteConfirmed(int id)
        {
            myUser myUser = db.myUsers.Find(id);

            myUser.FK_ActiveID = 2;
            db.SaveChanges();
            Session.Abandon();
            return(RedirectToAction("DoLogin", "BaeCoach"));
        }
示例#10
0
        public List <myUser> UpdateUser(myUser user, int id)
        {
            myUser createuser = new myUser()
            {
                posts = users[id - 1].posts, email = user.email, password = user.password, hash = myUser.hashPassword(user.password), profile = user.profile, username = user.username, user_id = id
            };

            users[id - 1] = createuser;
            return(users);
        }
示例#11
0
        public List <myUser> AddUser(myUser user)
        {
            myUser createuser = new myUser()
            {
                email = user.email, password = user.password, hash = myUser.hashPassword(user.password), profile = user.profile, username = user.username, user_id = users.Count + 1
            };

            users.Add(createuser);
            return(users);
        }
示例#12
0
        protected void logoutButton(object sender, EventArgs e)
        {
            OfficeChatDBEntities context = new OfficeChatDBEntities();
            int    u1    = (int)Session["curUserID"];
            myUser user1 = context.myUsers.Find(u1);

            user1.isOnline = 0;
            context.SaveChanges();
            Response.Redirect("Login.aspx");
        }
示例#13
0
    public static DataTable selectDataTable(myUser obj)
    {
        string strSQL = "select * from myuser where 1=1 ";

        if (obj.username != "" && obj.username != null)
        {
            strSQL = strSQL + "and username='******'";
        }

        DataTable dt = DBOper.execQueryBySQLText(strSQL);

        return(dt);
    }
示例#14
0
        // GET: myUsers/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            myUser myUser = db.myUsers.Find(id);

            if (myUser == null)
            {
                return(HttpNotFound());
            }
            return(View(myUser));
        }
示例#15
0
 public ActionResult Edit([Bind(Include = "UserID,Name,Surname,Username,FK_TitleID,FK_GenderID,FK_RelationshipStatusIdn,FK_ActiveID,FK_CityID,LoginID")] myUser myUser)
 {
     if (ModelState.IsValid)
     {
         db.Entry(myUser).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.FK_ActiveID = new SelectList(db.Actives, "ActiveID", "ActiveDescription", myUser.FK_ActiveID);
     ViewBag.FK_CityID   = new SelectList(db.Cities, "Id", "Name", myUser.FK_CityID);
     ViewBag.FK_GenderID = new SelectList(db.Genders, "GenderID", "GenderDescription", myUser.FK_GenderID);
     ViewBag.FK_RelationshipStatusIdn = new SelectList(db.RelationshipStatus, "RelationshipStatusID", "RelationshipStatusDescription", myUser.FK_RelationshipStatusIdn);
     ViewBag.FK_TitleID = new SelectList(db.Titles, "TitleID", "Titledescription", myUser.FK_TitleID);
     ViewBag.LoginID    = new SelectList(db.userLogins, "UserLoginID", "Username", myUser.LoginID);
     return(View(myUser));
 }
示例#16
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        myUser obj = new myUser();

        obj.username  = UserName.Text.Trim();
        obj.userkey   = Password.Text.Trim();
        obj.userphone = Phone.Text.Trim();
        if (myUser.selectDataTable(obj).Rows.Count != 0)
        {
            ComTool.Alert("注册失败,该用户名已存在!");
        }
        else if (myUser.insertRecord(obj) == 1)
        {
            ComTool.Alert("注册成功!");
            ComTool.Redirect(" Default.aspx");
        }
    }
示例#17
0
    public void getUser()
    {
        object phoneName = Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");


        string userId = Convert.ToBase64String((byte[])phoneName);

        BmobQuery queryUser = new BmobQuery();

        queryUser.WhereEqualTo("userId", userId);

        bmob.Find <myUser>(tableNameForUser, queryUser, (resp, exception) =>
        {
            if (exception != null)
            {
                showMessagem("查询异常" + exception.Message);

                return;
            }
            if (resp.results.Count == 0)
            {
                showMessagem("没有改用户  创建");

                user           = new myUser();
                user.userId    = userId;
                user.isPingJia = 0;
                user.userType  = 0;
                user.isJinYan  = 0;
                //  user.jinBi = help.zhuCeZengSong;
                user.niCheng = "匿名";
                addCaoZuo(user.jinBi, "登陆赠送", user.jinBi);
                string sheBei = DeviceExtendedProperties.GetValue("DeviceName").ToString(); //手机型号
                user.sheBei   = sheBei;
                creatUser();
            }

            else
            {
                showMessagem("查找到该用户" + resp.results[0]);
                user = resp.results[0];
                //    updataJinBi(new Random().NextDouble()-0.5, "随机操作用户金币");
            }
        });
    }
示例#18
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     if (UserName.Text.Trim() == "")
     {
         ComTool.Alert("请输入用户名!");
     }
     else if (Password.Text.Trim() == "")
     {
         ComTool.Alert("请输入密码!");
     }
     else
     {
         if (Int32.Parse(DropDownList1.SelectedItem.Value) == 0)
         {
             Admin obj = new Admin();
             obj.adminname = UserName.Text;
             obj.adminkey  = Password.Text;
             if (Admin.ifLogin(obj))
             {
                 ComTool.Alert("登陆成功!");
                 ComTool.Redirect("aroomstate.aspx");
             }
             else
             {
                 ComTool.Alert("登陆失败!");
             }
         }
         else if (Int32.Parse(DropDownList1.SelectedItem.Value) == 1)
         {
             myUser obj = new myUser();
             obj.username = UserName.Text;
             obj.userkey  = Password.Text;
             if (myUser.ifLogin(obj))
             {
                 ComTool.Alert("登陆成功!");
                 ComTool.Redirect("uroomstate.aspx");
             }
             else
             {
                 ComTool.Alert("登陆失败!");
             }
         }
     }
 }
示例#19
0
        public ActionResult LoginAction(string email, string password)
        {
            try
            {
                var    hashedPassword = ComputeSha256Hash(password);
                string newHased       = hashedPassword.Substring(0, 49);

                userLogin userLogin = db.userLogins.Where(z => z.Username == email && z.UserPassword == newHased).FirstOrDefault();
                myUser    user      = db.myUsers.Where(c => c.Username == email).FirstOrDefault();
                Coach     coach     = db.Coaches.Where(c => c.Username == email).FirstOrDefault();

                Session["userID"] = userLogin.UserLoginID;

                Session["LoggedUser"] = coach;
                Session["type"]       = userLogin.LoginType;

                if (user != null)
                {
                    Session["myUsersID"] = user.UserID;
                }
                else
                {
                    Session["myUsersID"] = coach.CoachID;
                }

                if (userLogin != null)
                {
                    return(RedirectToAction("TopicSelect", "BaeCoach"));
                }
                else
                {
                    ViewBag.Message = "UserName or password is wrong";
                    return(View());
                }
            }
            catch (Exception e)
            {
                ViewBag.Message = e.Message;
            }

            return(RedirectToAction("DoLogin"));
        }
示例#20
0
        // GET: myUsers/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            myUser myUser = db.myUsers.Find(id);

            if (myUser == null)
            {
                return(HttpNotFound());
            }
            ViewBag.FK_ActiveID = new SelectList(db.Actives, "ActiveID", "ActiveDescription", myUser.FK_ActiveID);
            ViewBag.FK_CityID   = new SelectList(db.Cities, "Id", "Name", myUser.FK_CityID);
            ViewBag.FK_GenderID = new SelectList(db.Genders, "GenderID", "GenderDescription", myUser.FK_GenderID);
            ViewBag.FK_RelationshipStatusIdn = new SelectList(db.RelationshipStatus, "RelationshipStatusID", "RelationshipStatusDescription", myUser.FK_RelationshipStatusIdn);
            ViewBag.FK_TitleID = new SelectList(db.Titles, "TitleID", "Titledescription", myUser.FK_TitleID);
            ViewBag.LoginID    = new SelectList(db.userLogins, "UserLoginID", "Username", myUser.LoginID);
            return(View(myUser));
        }
示例#21
0
    public static bool ifLogin(myUser obj)
    {
        bool   blRet  = true;
        string strSQL = "select * from myuser where username='******' "
                        + " and userkey='" + obj.userkey + "'";
        DataTable dt = DBOper.execQueryBySQLText(strSQL);

        try
        {
            if (dt.Rows.Count > 0)
            {
                blRet = true;
            }
            else
            {
                blRet = false;
            }
        }
        catch
        {
            blRet = false;
        }
        return(blRet);
    }
示例#22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int urgentflag = 0, receivedflag = 0;

            OfficeChatDBEntities context = new OfficeChatDBEntities();

            //getting user1 from session
            int    u1    = (int)Session["curUserID"];
            myUser user1 = context.myUsers.Find(u1);

            //setting up profile photo:
            Image pf = new Image();

            pf.ImageUrl = getProfilePhotoPath(user1);
            pf.CssClass = "profileImage rounded-circle float-right";
            profilePhoto.Controls.Add(pf);

            //get messages that are directed to user1 and unread then add them to the list (for no repetition)
            List <myUser> usersSending       = new List <myUser>();
            List <myUser> usersSendingUrgent = new List <myUser>();

            List <M_essage> msgs = context.M_essage.ToList();

            foreach (M_essage m in msgs)
            {
                if (m.ReceiverID.Equals(user1.UserID))
                {
                    myUser sendingUser = context.myUsers.Find(m.SenderID);
                    if (!usersSending.Contains(sendingUser) && !usersSendingUrgent.Contains(sendingUser))
                    {
                        if (m.isUrgent == 1 && m.isRead == 0)
                        {
                            usersSendingUrgent.Add(sendingUser);
                        }
                        else
                        {
                            usersSending.Add(sendingUser);
                        }
                    }
                }
            }
            //Go through the lists and add the users to the sidebar
            foreach (myUser sendingUser in usersSendingUrgent)
            {
                urgentflag   = 1;
                receivedflag = 1;
                string imagePath = getProfilePhotoPath(sendingUser);

                ImageButton but = new ImageButton();
                but.ImageUrl = imagePath;
                but.Width    = Unit.Pixel(50);
                but.Height   = Unit.Pixel(50);
                but.Click   += new ImageClickEventHandler(Button_Click);
                but.ID       = "b" + sendingUser.UserID;

                HtmlGenericControl div1 = new HtmlGenericControl("div");
                div1.Controls.Add(but);
                div1.Controls.Add(new LiteralControl(" " + sendingUser.N_ame + " [" + sendingUser.Title + "]"));

                div1.Attributes["class"] = "sidenavbardivUrgent";

                newChatHolder.Controls.Add(div1);
            }
            foreach (myUser sendingUser in usersSending)
            {
                receivedflag = 1;
                string imagePath = getProfilePhotoPath(sendingUser);

                ImageButton but = new ImageButton();
                but.ImageUrl      = imagePath;
                but.Width         = Unit.Pixel(50);
                but.Height        = Unit.Pixel(50);
                but.OnClientClick = "Button_Click";
                but.Click        += new ImageClickEventHandler(Button_Click);
                but.ID            = "b" + sendingUser.UserID;

                HtmlGenericControl div1 = new HtmlGenericControl("div");
                div1.Controls.Add(but);
                div1.Controls.Add(new LiteralControl(" " + sendingUser.N_ame + " [" + sendingUser.Title + "]"));

                div1.Attributes["class"] = "sidenavbardiv";

                newChatHolder.Controls.Add(div1);
            }
            //update message icon in top bar if needed
            if (receivedflag == 1)
            {
                msgLogo.Src = "Content/data/icons/msg.png";
            }
            if (urgentflag == 1)
            {
                msgLogo.Src = "Content/data/icons/msgUrg.png";
            }

            //row to hold them all
            HtmlGenericControl divRow = new HtmlGenericControl("div");

            divRow.Attributes["class"] = "row";

            //fill in users in same company
            List <myUser> users = context.myUsers.ToList();

            foreach (myUser u in users)
            {
                if (u.Company.Equals(user1.Company) && !u.Equals(user1))
                {
                    string imagePath = getProfilePhotoPath(u);

                    ImageButton but = new ImageButton();
                    but.ImageUrl = imagePath;
                    but.Width    = Unit.Pixel(100);
                    but.Height   = Unit.Pixel(100);
                    but.Click   += new ImageClickEventHandler(Button_Click);
                    but.ID       = "" + u.UserID;


                    HtmlGenericControl div1 = new HtmlGenericControl("div");
                    div1.Attributes["class"] = "col-xl-1 col-md-3 col-sm-4 vertical";
                    div1.Controls.Add(but);
                    div1.Controls.Add(new LiteralControl("<h4>" + u.N_ame + "</h4><h6>" + u.Title + "</h6>"));

                    divRow.Controls.Add(div1);
                }
            }
            //and new row of contacts into chatfield
            contactsField.Controls.Add(divRow);
            context.SaveChanges();
        }
示例#23
0
        protected void Page_Load(object sender, EventArgs e)
        {
            OfficeChatDBEntities context = new OfficeChatDBEntities();
            int    u1    = (int)Session["curUserID"];
            myUser user1 = context.myUsers.Find(u1);

            if (IsPostBack)
            {
                string   name  = String.Format("{0}", Request.Form["Text1"]);
                string   gend  = String.Format("{0}", Request.Form["Text2"]);
                string   email = String.Format("{0}", Request.Form["Text3"]);
                DateTime start = DateTime.Parse(Request.Form["Text4"]);
                string   title = String.Format("{0}", Request.Form["Text5"]);
                string   comp  = String.Format("{0}", Request.Form["Text6"]);
                string   pass  = String.Format("{0}", Request.Form["Text7"]);
                string   role  = String.Format("{0}", Request.Form["Text8"]);

                Company c = null;
                foreach (Company cmp in context.Companies)
                {
                    if (cmp.N_ame.Equals(comp))
                    {
                        c = cmp;
                        break;
                    }
                }

                user1.N_ame          = name;
                user1.Gender         = gend;
                user1.Email          = email;
                user1.Title          = title;
                user1.StartedWorking = start;
                user1.Role           = role;
                user1.P_assword      = pass;

                if (c != null)
                {
                    user1.Company = c.CID;
                    context.SaveChanges();
                }
                else
                {
                    errorHolder.InnerHtml = "<h4 style='color:red'> Company does not exist </h4>";
                }
            }

            /* Removed admin ability to edit/delete users
             * foreach (myUser u in context.myUsers.ToList())
             * {
             *  TableRow row = new TableRow();
             *  TableCell cell0 = new TableCell();
             *  cell0.Text = "<img src=" + getfilepath(u) + " class='image'/>";
             *  row.Cells.Add(cell0);
             *  TableCell cell1 = new TableCell();
             *  cell1.Text = u.N_ame;
             *  row.Cells.Add(cell1);
             *  TableCell cell2 = new TableCell();
             *  cell2.Text = "<a href='UserManagerAdmin.aspx?id='"+u.UserID+"'&>Manage</a>";
             *  row.Cells.Add(cell2);
             *  companyList.Rows.Add(row);
             * }
             */
        }
示例#24
0
        protected void Page_Load(object sender, EventArgs e)
        {
            OfficeChatDBEntities context = new OfficeChatDBEntities();
            int    u1    = (int)Session["curUserID"];
            myUser user1 = context.myUsers.Find(u1);

            if (IsPostBack)
            {
                string   name  = String.Format("{0}", Request.Form["Text1"]);
                string   gend  = String.Format("{0}", Request.Form["Text2"]);
                string   email = String.Format("{0}", Request.Form["Text3"]);
                DateTime start = DateTime.Parse(Request.Form["Text4"]);
                string   title = String.Format("{0}", Request.Form["Text5"]);
                string   comp  = String.Format("{0}", Request.Form["Text6"]);

                Company c = null;
                foreach (Company cmp in context.Companies)
                {
                    if (cmp.N_ame.Equals(comp))
                    {
                        c = cmp;
                        break;
                    }
                }
                user1.N_ame          = name;
                user1.Gender         = gend;
                user1.Email          = email;
                user1.Title          = title;
                user1.StartedWorking = start;

                HttpPostedFile postedFile = Request.Files["FileUpload"];
                if (postedFile != null && postedFile.ContentLength > 0)
                {
                    string filePath = Server.MapPath("tmpFiles/") + Path.GetFileName(postedFile.FileName);

                    postedFile.SaveAs(filePath);


                    FileHolder fh = new FileHolder();
                    fh.FName = "~/tmpFiles/" + Path.GetFileName(postedFile.FileName);

                    context.FileHolders.Add(fh);
                    user1.PhotoRef = fh.FID;
                }

                if (c != null)
                {
                    user1.Company = c.CID;
                    context.SaveChanges();
                }
                else
                {
                    errorHolder.InnerHtml = "<h4 style='color:red'> Company does not exist </h4>";
                }
            }
            else
            {
                Text1.Value = user1.N_ame;
                Text2.Value = user1.Gender;
                Text3.Value = user1.Email;
                Text4.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(' ', 'T');
                Text5.Value = user1.Title;
                string cname = context.Companies.Find((int)user1.Company).N_ame;
                Text6.Value = cname;

                Image img = new Image();
                img.ImageUrl = getfilepath(user1);
                img.Height   = Unit.Pixel(100);
                img.Width    = Unit.Pixel(100);

                imageHere.Controls.Add(img);
            }
        }
示例#25
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int urgentflag = 0, receivedflag = 0;

            OfficeChatDBEntities context = new OfficeChatDBEntities();
            List <M_essage>      msgs    = context.M_essage.ToList();


            //remove any spam messages
            foreach (M_essage ms in msgs)
            {
                if (ms.T_ext == null)
                {
                    context.M_essage.Remove(ms);
                    context.SaveChanges();
                }
            }

            //getting users
            int    u1    = (int)Session["curUserID"];
            myUser user1 = context.myUsers.Find(u1);
            int    u2    = int.Parse((string)Session["user2"]);
            myUser user2 = context.myUsers.Find(u2);

            //setting up profile photo:
            Image pf = new Image();

            pf.ImageUrl = getProfilePhotoPath(user1);
            pf.CssClass = "profileImage rounded-circle float-right";
            profilePhoto.Controls.Add(pf);

            List <myUser> users = context.myUsers.ToList();

            //add user2 image, name, and status at top:
            string imagepath = getProfilePhotoPath(user2);
            string status    = "Offline";
            string color     = "red";

            if (user2.isOnline == 1)
            {
                status = "Online";
                color  = "green";
            }

            user2Dets.InnerHtml = "<img src='" + imagepath + "' class='profileImageTo rounded-circle'/>"
                                  + "<span style = 'font-size:20px' > " + user2.N_ame + " </span>"
                                  + "<span style = 'color:" + color + "'> " + status + " </span>"
                                  + "<a href=\"index.aspx?\"> X </a>";
            M_essage mes = new M_essage();

            if (Request.QueryString["sending"] == "1" && IsPostBack) //text message
            {
                //Add typed message to database
                mes.timeSent   = System.DateTime.Now;
                mes.SenderID   = user1.UserID;
                mes.ReceiverID = user2.UserID;
                mes.isRead     = 0;
                mes.isUrgent   = 0;
                mes.isDeleted  = 0;
                mes.isText     = 1;
                mes.isFile     = 0;
                mes.T_ext      = Request.Form["messageIn"];

                if (Checkbox1.Checked == true)
                {
                    mes.isUrgent = 1;
                }
                if (mes.T_ext != "")
                {
                    context.M_essage.Add(mes);
                }
                context.SaveChanges();
            }
            HttpPostedFile postedFile = Request.Files["fileupload"];

            if (postedFile != null && postedFile.ContentLength > 0)//file was uploaded
            {
                mes.isFile = 1;

                string filePath = Server.MapPath("tmpFiles/") + Path.GetFileName(postedFile.FileName);

                postedFile.SaveAs(filePath);

                FileHolder fh = new FileHolder();
                fh.FName    = "tmpFiles/" + Path.GetFileName(postedFile.FileName);
                mes.FileRef = fh.FID;
                context.FileHolders.Add(fh);
                context.SaveChanges();
            }

            msgs = context.M_essage.ToList(); //refreshing messages list

            chatField.InnerHtml = "~Beginning of chat with " + user2.N_ame;

            //get messages/fileRefs from database with right sender/receiver and add them in order
            foreach (M_essage m in msgs)
            {
                //setting up read string
                string readString = "Not read yet";
                if (m.isRead == 1)
                {
                    readString = m.timeRead.ToString();
                }
                //form user2 to user1
                if (m.SenderID.Equals(user1.UserID) && m.ReceiverID.Equals(user2.UserID))
                {
                    if (m.isText == 1)
                    {
                        if (m.isUrgent == 1)
                        {
                            chatField.InnerHtml = chatField.InnerHtml + "<div class =\"row user2 urgent\"> Sent: " + m.timeSent + " Read: " + readString + " <br/>" + m.T_ext + " </div>";
                        }
                        else //not urgent
                        {
                            chatField.InnerHtml = chatField.InnerHtml + "<div class =\"row user2\"> " + m.timeSent + " Read: " + readString + " <br/>" + m.T_ext + " </div>";
                        }
                    }
                    if (m.isFile == 1) //file/photo
                    {
                        FileHolder fh2      = context.FileHolders.Find(m.FileRef);
                        String     filepath = fh2.FName;
                        String     ext3     = filepath.Substring(filepath.Length - 4); // .png .jpg
                        String     ext4     = filepath.Substring(filepath.Length - 5); // .jpeg
                        if (ext3.Equals(".png") || ext3.Equals(".jpg") || ext4.Equals(".jpeg"))
                        {
                            chatField.InnerHtml = chatField.InnerHtml + "<div class =\"row user2\"> <img src = '" + fh2.FName + "' class='imgupload'> </div>";
                        }
                        else //non image file
                        {
                            string filename = filepath.Split('/')[1];
                            chatField.InnerHtml = chatField.InnerHtml + "<div class =\"row user2\"> <a href='" + fh2.FName + "' download> <img src='Content/data/icons/download.png' class='btnIcon icon'/> Download " + filename + "</a></div>";
                        }
                    }
                }
                //user1 to user2
                else if (m.SenderID.Equals(user2.UserID) && m.ReceiverID.Equals(user1.UserID))
                {
                    if (m.isText == 1)
                    {
                        if (m.isUrgent == 1)
                        {
                            chatField.InnerHtml = chatField.InnerHtml + "<div class =\"row user1 urgent\"> " + m.timeSent + " Read: " + readString + " <br/>" + m.T_ext + " </div>";
                        }
                        else //not urgent
                        {
                            chatField.InnerHtml = chatField.InnerHtml + "<div class =\"row user1\"> " + m.timeSent + " Read: " + readString + " <br/>" + m.T_ext + " </div>";
                        }
                    }
                    if (m.isFile == 1) //file/photo
                    {
                        FileHolder fh2      = context.FileHolders.Find(m.FileRef);
                        String     filepath = fh2.FName;
                        String     ext3     = filepath.Substring(filepath.Length - 4); // .png .jpg
                        String     ext4     = filepath.Substring(filepath.Length - 5); // .jpeg
                        if (ext3.Equals(".png") || ext3.Equals(".jpg") || ext4.Equals(".jpeg"))
                        {
                            chatField.InnerHtml = chatField.InnerHtml + "<div class =\"row user2\"> <img src = '" + fh2.FName + "' class='imgupload'> </div>";
                        }
                        else //non image file
                        {
                            string filename = filepath.Split('/')[1];
                            chatField.InnerHtml = chatField.InnerHtml + "<div class =\"row user2\"> <button onclick=\"javascript: window.location = '" + fh2.FName + "'\" class='ButtonDownload'> <img src='Content/data/icons/download.png' class='btnIcon icon'/> Download " + filename + "</button></div>";
                        }
                    }
                    if (m.isRead == 0)
                    {
                        m.isRead   = 1;
                        m.timeRead = System.DateTime.Now;
                    }
                }
            }
            context.SaveChanges();

            //Filling sidebar
            //get messages that are directed to user1 and unread then add them to the list (for no repetition)
            List <myUser> usersSending       = new List <myUser>();
            List <myUser> usersSendingUrgent = new List <myUser>();

            foreach (M_essage m in msgs)
            {
                //if directed to user1
                if (m.ReceiverID.Equals(user1.UserID))
                {
                    myUser sendingUser = context.myUsers.Find(m.SenderID);
                    if (!usersSending.Contains(sendingUser) && !usersSendingUrgent.Contains(sendingUser))
                    {
                        if (m.isUrgent == 1 && m.isRead == 0)
                        {
                            usersSendingUrgent.Add(sendingUser);
                        }
                        else
                        {
                            usersSending.Add(sendingUser);
                        }
                    }
                }
            }
            //Go through the lists and add the users to the sidebar
            foreach (myUser sendingUser in usersSendingUrgent)
            {
                urgentflag   = 1;
                receivedflag = 1;
                string imagePath = getProfilePhotoPath(sendingUser);

                ImageButton but = new ImageButton();
                but.ImageUrl = imagePath;
                but.Width    = Unit.Pixel(50);
                but.Height   = Unit.Pixel(50);
                but.Click   += new ImageClickEventHandler(Button_Click);
                but.ID       = "" + sendingUser.UserID;

                HtmlGenericControl div1 = new HtmlGenericControl("div");
                div1.Controls.Add(but);
                div1.Controls.Add(new LiteralControl(" " + sendingUser.N_ame + " [" + sendingUser.Title + "]"));

                div1.Attributes["class"] = "sidenavbardivurgent";

                newChatHolder.Controls.Add(div1);
            }
            foreach (myUser sendingUser in usersSending)
            {
                receivedflag = 1;
                string imagePath = getProfilePhotoPath(sendingUser);

                ImageButton but = new ImageButton();
                but.ImageUrl      = imagePath;
                but.Width         = Unit.Pixel(50);
                but.Height        = Unit.Pixel(50);
                but.OnClientClick = "Button_Click";
                but.Click        += new ImageClickEventHandler(Button_Click);
                but.ID            = "" + sendingUser.UserID;

                HtmlGenericControl div1 = new HtmlGenericControl("div");
                div1.Controls.Add(but);
                div1.Controls.Add(new LiteralControl(" " + sendingUser.N_ame + " [" + sendingUser.Title + "]"));

                div1.Attributes["class"] = "sidenavbardiv";

                newChatHolder.Controls.Add(div1);
            }
            //update message icon in top bar if needed
            if (receivedflag == 1)
            {
                msgLogo.Src = "Content/data/icons/msg.png";
            }
            if (urgentflag == 1)
            {
                msgLogo.Src = "Content/data/icons/msgUrg.png";
            }
            //refresh entire page
            System.Threading.Thread.Sleep(1500);
            HttpContext.Current.RewritePath("indexChat.aspx/sending=0");

            context.SaveChanges();
        }