Ejemplo n.º 1
0
 public override string GetUserNameByEmail(string email)
 {
     using (AutenticationEntities dbContext = new AutenticationEntities())
     {
         string username = (from u in dbContext.User
                            where string.Compare(email, u.Email) == 0
                            select u.UserName).FirstOrDefault();
         return(!string.IsNullOrEmpty(username) ? username : string.Empty);
     }
     throw new NotImplementedException();
 }
Ejemplo n.º 2
0
 public override MembershipUser GetUser(string username, bool userIsOnline)
 {
     // throw new NotImplementedException();
     using (AutenticationEntities dbContext = new AutenticationEntities())
     {
         var user = (from us in dbContext.User
                     where string.Compare(username, us.UserName, StringComparison.OrdinalIgnoreCase) == 0
                     select us).FirstOrDefault();
         if (user == null)
         {
             return(null);
         }
         var selectUser = new CustomMembershipUser(user);
         return(selectUser);
     }
 }
Ejemplo n.º 3
0
        public override bool ValidateUser(string username, string password)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(false);
            }

            using (AutenticationEntities dbContext = new AutenticationEntities())
            {
                var user = (from us in dbContext.User
                            where string.Compare(username, us.UserName, StringComparison.OrdinalIgnoreCase) == 0 &&
                            string.Compare(password, us.Password, StringComparison.OrdinalIgnoreCase) == 0 &&
                            us.IsActive == true
                            select us).FirstOrDefault();

                return((user != null) ? true : false);
            }
        }
Ejemplo n.º 4
0
        public override string[] GetRolesForUser(string username)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return(null);
            }
            var userRoles = new string[] { };

            using (AutenticationEntities dbContex = new AutenticationEntities())
            {
                var selectUser = (from us in dbContex.User.Include("Role")
                                  where string.Compare(us.UserName, username) == 0
                                  select us).FirstOrDefault();
                if (selectUser != null)
                {
                    userRoles = new[] { selectUser.Roles.RoleName.ToString() };
                }
                return(userRoles.ToArray());
            }
        }
        public ActionResult ActivationAccount(int id)
        {
            bool statusAccount = false;

            using (AutenticationEntities dbContext = new AutenticationEntities()) {
                var userAccount = dbContext.User.Where(u => u.UserId == id).FirstOrDefault();

                if (userAccount != null)
                {
                    userAccount.IsActive = true;
                    dbContext.SaveChanges();
                    statusAccount = true;
                }
                else
                {
                    ViewBag.Message = "Something Wrong !!";
                }
            }
            ViewBag.Status = statusAccount;
            return(View());
        }
        public ActionResult Registration(RegisterViewModel registration)
        {
            bool   status = false;
            string messageRegistration = string.Empty;

            if (ModelState.IsValid)
            {
                string userName = Membership.GetUserNameByEmail(registration.Email);
                if (!string.IsNullOrEmpty(userName))
                {
                    ModelState.AddModelError("Warning Email", "Sorry : Email alreadyExist");
                    return(View(registration));
                }

                using (AutenticationEntities dbContext = new AutenticationEntities())
                {
                    var user = new User()
                    {
                        UserName = registration.Email,
                        Password = registration.Password,
                    };
                    dbContext.User.Add(user);
                    dbContext.SaveChanges();
                }
                VerificationEmail(registration.Email, "0001");
                messageRegistration = "Your Account has been created successfully";
                status = true;
            }
            else
            {
                messageRegistration = "Something Worng!";
            }
            ViewBag.Message = messageRegistration;
            ViewBag.Status  = status;

            return(RedirectToAction("Index"));
        }