Exemple #1
0
        /// <summary>
        /// Authenticates the user.
        /// </summary>
        ///<param name="username">Username</param>
        ///<param name="password">Password</param>
        /// <returns>bool</returns>
        public override bool ValidateUser(string username, string password)
        {
            // Lookup user in database, web service, etc. We'll just generate a fake user for this demo.
            DBModelContainer db = new DBModelContainer();

            Models.User userEntity = db.Users
                                     .Include(i => i.Carts)
                                     .Where(i => (i.UserName == username && i.Password == password))
                                     .FirstOrDefault();
            if (userEntity != null)
            {
                // Store the user temporarily in the context for this request.
                FormsAuth.Models.User user = new FormsAuth.Models.User {
                    Id       = userEntity.UserId,
                    Username = userEntity.UserName
                };
                HttpContext.Current.Items.Add("User", user);

                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Authenticates the user.
        /// </summary>
        ///<param name="username">Username</param>
        ///<param name="password">Password</param>
        /// <returns>bool</returns>
        public override bool ValidateUser(string username, string password)
        {
            // Lookup user in database, web service, etc. We'll just generate a fake user for this demo.
            AccountService service = new AccountService();

            Models.User userEntity = Task.Run(() => service.authenticate(username, password)).Result;

            if (userEntity != null)
            {
                // Store the user temporarily in the context for this request.
                FormsAuth.Models.User user = new FormsAuth.Models.User {
                    Id       = userEntity.UserId,
                    Username = userEntity.UserName
                };
                HttpContext.Current.Items.Add("User", user);

                return(true);
            }
            else
            {
                return(false);
            }
        }