コード例 #1
0
        public override string GetUserNameByEmail(string email)
        {
            using (var db = new MassDataEducationEntities())
            {
                string username = (from reg in db.Person
                                   where string.Compare(email, reg.Email) == 0
                                   select reg.Name).FirstOrDefault();

                return(!string.IsNullOrEmpty(username) ? username : string.Empty);
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="userIsOnline"></param>
        /// <returns></returns>
        public override MembershipUser GetUser(string PersonID, bool userIsOnline)
        {
            using (var db = new MassDataEducationEntities())
            {
                var user = (from us in db.Person
                            where string.Compare(PersonID, us.Id, StringComparison.OrdinalIgnoreCase) == 0
                            select us).FirstOrDefault();

                if (user == null)
                {
                    return(null);
                }
                var selectedUser = new CustomMembershipUser(user);

                return(selectedUser);
            }
        }
コード例 #3
0
        public ActionResult Login(LoginVM login, string ReturnUrl = "")
        {
            if (ModelState.IsValid)
            {
                var db   = new MassDataEducationEntities();
                var data = db.Person.ToList();
                if (Membership.ValidateUser(login.Id, login.Password))
                {
                    var user     = (CustomMembershipUser)Membership.GetUser(login.Id, false);
                    var userdata = db.Person.Find(user.Id);
                    //var registration = db.Person.Find(user.Id);

                    if (user != null)
                    {
                        CustomSerializeModel userModel = new CustomSerializeModel()
                        {
                            Id          = userdata.Id,
                            Name        = userdata.Name,
                            Email       = userdata.Email,
                            Image       = userdata.Image,
                            InstituteID = Convert.ToInt32(userdata.InstituteID),
                            UserType    = userdata.Type
                        };

                        string userData = JsonConvert.SerializeObject(userModel);
                        FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, login.Id, DateTime.Now, DateTime.Now.AddMinutes(15), false, userData);

                        string     enTicket = FormsAuthentication.Encrypt(authTicket);
                        HttpCookie faCookie = new HttpCookie("Cookie1", enTicket);
                        Response.Cookies.Add(faCookie);
                    }

                    if (Url.IsLocalUrl(ReturnUrl))
                    {
                        return(Redirect(ReturnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
            ModelState.AddModelError("", "Invalid Username or Password");
            return(View(login));
        }
コード例 #4
0
ファイル: CustomRole.cs プロジェクト: Shakil-Ahmmad/MDLSP01
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public override string[] GetRolesForUser(string PersonID)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return(null);
            }

            var userRoles = new string[] { };

            using (var db = new MassDataEducationEntities())
            {
                var selectedUser = (from us in db.Person
                                    where string.Compare(us.Id, PersonID, StringComparison.OrdinalIgnoreCase) == 0
                                    select us).FirstOrDefault();

                return(new string[] { selectedUser.Type });
            }
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public override bool ValidateUser(string PersonID, string Password)
        {
            if (string.IsNullOrEmpty(PersonID) || string.IsNullOrEmpty(Password))
            {
                return(false);
            }

            using (var db = new MassDataEducationEntities())
            {
                var user = (from us in db.Person
                            where string.Compare(PersonID, us.Id, StringComparison.OrdinalIgnoreCase) == 0 &&
                            us.Password == Password &&
                            us.Deleted == false
                            select us).FirstOrDefault();

                return((user != null) ? true : false);
            }
        }