예제 #1
0
        public object ChangePassword( PassWordChange passWordChange )
        {
            AccountUser retorno = new AccountUser();

            try
            {
                IUsuario usuario = this.model.ChangePassword(passWordChange.IdUsuario
                , passWordChange.CurrentPassword
                , passWordChange.NewPassword
                , passWordChange.ConfirmPassword);

                retorno = this.model.GetAccount(usuario.UsuarioId);
            }
            catch( Exception ex )
            {
                var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(ex.Message) ,
                    ReasonPhrase = "Error!"
                };
                throw new HttpResponseException(resp);
            }

            var simpleResult = CleanUser(retorno);

            return simpleResult;
        }
예제 #2
0
        public IProfile ProfileExists(AccountUser usuario)
        {
            IDataQuery query = new DataQuery();

            query.Where = string.Format("customId='{0}'", Security.ClearSQLInjection(usuario.CustomId));

            IList <IUsuario> result  = _repository.Find(query);
            IProfile         profile = new Profile();

            if (result.Count > 0)
            {
                query.Where = string.Format("userId={0} and removed=0", result[0].UsuarioId);
                profile     = _repositoryProfile.Find(query)[0];
            }

            return(profile);
        }
예제 #3
0
        public object Create( AccountUser accountUser )
        {
            IProfile profile = new Profile();
            AccountUser retorno = new AccountUser();

            if( !String.IsNullOrEmpty(accountUser.CustomId) )
            {
                profile = this.model.ProfileExists(accountUser);
            }

            if( profile.UserId == 0 )
            {
                profile = this.model.CreateAccount(accountUser);
            }

            retorno = this.model.GetAccount(profile.UserId);

            var simpleResult = CleanUser(retorno);

            return simpleResult;
        }
예제 #4
0
        public IProfile CreateAccount(AccountUser usuario)
        {
            IProfile result = new Profile();

            using (TransactionScope scope = new TransactionScope())
            {
                usuario.Created = DateTime.Now;
                usuario.City = Security.ClearSQLInjection(usuario.City);
                usuario.Country = Security.ClearSQLInjection(usuario.Country);
                usuario.CustomId = Security.ClearSQLInjection(usuario.CustomId);
                usuario.Email = Security.ClearSQLInjection(usuario.Email);
                usuario.Name = Security.ClearSQLInjection(usuario.Name);
                usuario.Password = Security.ClearSQLInjection(usuario.Password);
                usuario.Picture = Security.ClearSQLInjection(usuario.Picture);
                usuario.Gender = Security.ClearSQLInjection(usuario.Gender);

                string emailcrypted = Security.Encrypt(usuario.Email);
                string passw = PasswordHash.CreateHash(usuario.Password);

                usuario.Email = emailcrypted;
                usuario.Password = passw;

                IUsuario iusuario = _repository.Add(usuario);

                ProfileRepository profile = new ProfileRepository(_dataBase);
                IProfile newProfile = new Profile();
                newProfile.UserId = iusuario.UsuarioId;
                newProfile.Upadted = DateTime.Now;
                newProfile.Picture = Security.ClearSQLInjection(usuario.Picture);
                result = profile.Add(newProfile);

                scope.Complete();
            }

            return result;
        }
예제 #5
0
        public IProfile CreateAccount(AccountUser usuario)
        {
            IProfile result = new Profile();

            using (TransactionScope scope = new TransactionScope())
            {
                usuario.Created  = DateTime.Now;
                usuario.City     = Security.ClearSQLInjection(usuario.City);
                usuario.Country  = Security.ClearSQLInjection(usuario.Country);
                usuario.CustomId = Security.ClearSQLInjection(usuario.CustomId);
                usuario.Email    = Security.ClearSQLInjection(usuario.Email);
                usuario.Name     = Security.ClearSQLInjection(usuario.Name);
                usuario.Password = Security.ClearSQLInjection(usuario.Password);
                usuario.Picture  = Security.ClearSQLInjection(usuario.Picture);
                usuario.Gender   = Security.ClearSQLInjection(usuario.Gender);

                string emailcrypted = Security.Encrypt(usuario.Email);
                string passw        = PasswordHash.CreateHash(usuario.Password);

                usuario.Email    = emailcrypted;
                usuario.Password = passw;

                IUsuario iusuario = _repository.Add(usuario);

                ProfileRepository profile    = new ProfileRepository(_dataBase);
                IProfile          newProfile = new Profile();
                newProfile.UserId  = iusuario.UsuarioId;
                newProfile.Upadted = DateTime.Now;
                newProfile.Picture = Security.ClearSQLInjection(usuario.Picture);
                result             = profile.Add(newProfile);

                scope.Complete();
            }

            return(result);
        }
예제 #6
0
        private object CleanUser( AccountUser pAccountUser)
        {
            var retorno =  new {
                    Birthdate = pAccountUser.Birthdate,
                    City = pAccountUser.City,
                    Country = pAccountUser.Country,
                    CustomId = pAccountUser.CustomId,
                    Name = pAccountUser.Name,
                    Picture = pAccountUser.Picture,
                    ProfileId = pAccountUser.ProfileId,
                    UserId = pAccountUser.UserId
                };

                return retorno;
        }
예제 #7
0
        public object UserUpdate( AccountUser accountUser )
        {
            IUsuario usuario = this.model.UpdateAccount((IUsuario)accountUser);
            AccountUser retorno = this.model.GetAccount(usuario.UsuarioId);

            var simpleResult = CleanUser(retorno);

            return simpleResult;
        }
예제 #8
0
        public object UserDetails( int id )
        {
            AccountUser profile = new AccountUser();

            profile = this.model.GetAccount(id);

            var simpleResult = CleanUser(profile);

            return simpleResult;
        }
예제 #9
0
        public object SignIn( AccountUser accountUser )
        {
            IUsuario usuario = this.model.SignIn(accountUser.Password, accountUser.Email);
            AccountUser retorno = this.model.GetAccount(usuario.UsuarioId);

            if( retorno.UsuarioId == 0 )
            {
                var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(string.Format("No user found!" , accountUser.Email)) ,
                    ReasonPhrase = "User not Found"
                };
                throw new HttpResponseException(resp);
            }

            var simpleResult = CleanUser(retorno);

            return simpleResult;
        }
예제 #10
0
        public IProfile ProfileExists(AccountUser usuario)
        {
            IDataQuery query = new DataQuery();
            query.Where = string.Format("customId='{0}'", Security.ClearSQLInjection(usuario.CustomId));

            IList<IUsuario> result = _repository.Find(query);
            IProfile profile = new Profile();

            if (result.Count > 0)
            {
                query.Where = string.Format("userId={0} and removed=0", result[0].UsuarioId);
                profile = _repositoryProfile.Find(query)[0];
            }

            return profile;
        }
예제 #11
0
        public AccountUser GetAccount(int userId)
        {
            AccountUser retorno = new AccountUser();

            IDataQuery query = new DataQuery();
            query.Where = string.Format("usuarioId={0}", userId);
            IList<IUsuario> result = _repository.Find(query);
            IProfile profile = new Profile();
            IUsuario usuario = new Usuario();

            if (result.Count > 0)
            {
                usuario = result[0];
                query.Where = string.Format("userId={0} and removed=0", result[0].UsuarioId);
                profile = _repositoryProfile.Find(query)[0];

                retorno.Birthdate = usuario.Birthdate;
                retorno.Created = usuario.Created;
                retorno.CustomId = usuario.CustomId;
                retorno.Email = usuario.Email;
                retorno.Gender = usuario.Gender;
                retorno.Name = usuario.Name;
                retorno.UsuarioId = usuario.UsuarioId;
                retorno.City = usuario.City;
                retorno.Country = usuario.Country;

                retorno.Picture = profile.Picture;
                retorno.ProfileId = profile.ProfileId;
                retorno.UserId = profile.UserId;
            }

            return retorno;
        }