private void DataPortal_Fetch(LoginCriteria criteria)
        {
            if (criteria.IsGuest)
            {
                this.FetchGuest();
            }
            else
            {
                using (var ctx = ObjectContextManager<ApplicationEntities>
                    .GetManager(Database.SecurityConnection, false))
                {
                    IQueryable<Data.User> query = ctx.ObjectContext.Users;

                    query = query.Where(row => row.Name == criteria.Name
                        || row.Email == criteria.Name);

                    var data = query.Select(row => row);

                    if (data.Count() > 0)
                    {
                        var user = data.Single();

                        if (!string.IsNullOrEmpty(criteria.Password))
                        {
                            if (PasswordHelper.ComparePasswords(
                                user.Salt,
                                criteria.Password,
                                user.Password))
                            {
                                this.Fetch(user);
                            }
                            else
                            {
                                throw new SecurityException("User name or password is invalid.");
                            }
                        }
                        else
                        {
                            this.Fetch(user);
                        }
                    }
                    else
                    {
                        throw new SecurityException("User name or password is invalid.");
                    }
                }
            }
        }
Esempio n. 2
0
        private void DataPortal_Fetch(LoginCriteria criteria)
        {
            if (criteria.IsGuest)
            {
                this.FetchGuest();
            }
            else
            {
                using (var ctx = ObjectContextManager <ApplicationEntities>
                                 .GetManager(Database.SecurityConnection, false))
                {
                    IQueryable <Data.User> query = ctx.ObjectContext.Users;

                    query = query.Where(row => row.Name == criteria.Name ||
                                        row.Email == criteria.Name);

                    var data = query.Select(row => row);

                    if (data.Count() > 0)
                    {
                        var user = data.Single();

                        if (!string.IsNullOrEmpty(criteria.Password))
                        {
                            if (PasswordHelper.ComparePasswords(
                                    user.Salt,
                                    criteria.Password,
                                    user.Password))
                            {
                                this.Fetch(user);
                            }
                            else
                            {
                                throw new SecurityException("User name or password is invalid.");
                            }
                        }
                        else
                        {
                            this.Fetch(user);
                        }
                    }
                    else
                    {
                        throw new SecurityException("User name or password is invalid.");
                    }
                }
            }
        }