Exemple #1
0
        void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e)
        {
            HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
            if (authCookie != null)
            {
                FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
                if (authTicket == null || authTicket.Expired)
                {
                    return;
                }

                Identity id = new Identity(authTicket.Name, authTicket.UserData);
                GenericPrincipal user = new GenericPrincipal(id, null);
                Context.User = user;
                Thread.CurrentPrincipal = user;
            }
        }
        public ActionResult Login(LoginUser user)
        {
            if (ModelState.IsValid)
            {
                AdobeConnectXmlAPI con = new AdobeConnectXmlAPI();
                StatusInfo sInfo;
                if (con.Login(user.Username, user.Password, out sInfo))
                {
                    int id = int.Parse(con.GetUserInfo().user_id);
                    Identity Id = new Identity( id , user.Username, "T");
                    DateTime expire = DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes);
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(Id.ID, user.Username, DateTime.Now, expire, false, Id.GetUserData());
                    string hashTicket = FormsAuthentication.Encrypt(ticket);
                    HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashTicket);
                    HttpContext.Response.Cookies.Add(cookie);
                    UserSession userSession = new UserSession(con.GetMyMeetings(), con.GetUserInfo());
                    using (AdobeConnectDB _db = new AdobeConnectDB()) {
                        var check = _db.AdobeUserInfo.Where(u => u.Username == user.Username).FirstOrDefault();
                        if (check == null)
                        {
                            var newlogin = new LoginUser();
                            newlogin.Username = user.Username;
                            newlogin.Password = user.Password;
                            newlogin.Id = id;
                            _db.AdobeUserInfo.Add(newlogin);
                            _db.SaveChanges();
                        }
                        else
                        {
                            check = user;
                            _db.SaveChanges();
                        }

                    }
                    Session["UserSession"] = userSession;
                }
                else {
                    return View("Login");
               }

            }

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