示例#1
0
        public static bool UploadS3(MAwsS3 mAwsS3, string localFilePath, string subDirectoryInBucket, string fileNameInS3)
        {
            try
            {
                AWSCredentials credentials;
                credentials = new BasicAWSCredentials(UEncrypt.Decrypt(mAwsS3.AccessKey.Trim()), UEncrypt.Decrypt(mAwsS3.SecretKey.Trim()));
                IAmazonS3 client = new AmazonS3Client(credentials, RegionEndpoint.USEast2);

                TransferUtility utility = new TransferUtility(client);
                TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();

                if (subDirectoryInBucket == "" || subDirectoryInBucket == null)
                {
                    request.BucketName = UEncrypt.Decrypt(mAwsS3.BucketName); //no subdirectory just bucket name
                }
                else
                { // subdirectory and bucket name
                    request.BucketName = UEncrypt.Decrypt(mAwsS3.BucketName) + @"/" + subDirectoryInBucket;
                }

                request.Key       = fileNameInS3;  //file name up in S3
                request.FilePath  = localFilePath; //local file name
                request.CannedACL = S3CannedACL.PublicRead;
                utility.Upload(request);           //commensing the transfer

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#2
0
        public CreateDonorResponse ChangePasswordDonor([FromBody] DonorRequest request)
        {
            CreateDonorResponse response = new CreateDonorResponse();
            MDonor      donor            = new MDonor();
            BaseRequest baseRequest      = new BaseRequest();

            try
            {
                /*METODO QUE VALIDA EL TOKEN DE APLICACIÓN*/
                if (!BAplication.ValidateAplicationToken(request.ApplicationToken))
                {
                    response.Code    = "2";
                    response.Message = Messages.ApplicationTokenNoAutorize;
                    return(response);
                }
                /*************FIN DEL METODO*************/

                donor.DonorId     = request.Donor.DonorId;
                donor.Email       = request.Donor.Email;//donor.Cellphone = request.Donor.Cellphone;
                donor.Password    = UEncrypt.Encrypt(request.Donor.Password);
                donor.OldPassword = UEncrypt.Encrypt(request.Donor.OldPassword);

                baseRequest.Session = request.Session;

                if (BSession.ValidateSession(1, baseRequest.Session.Token, baseRequest.Session.UserId).Equals(1))
                {
                    int CodeResult = BDonor.ChangePassword(donor);
                    response.Code = CodeResult.ToString(); //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción

                    if (CodeResult == 0)
                    {
                        response.Message = Messages.Success;
                    }
                    else if (CodeResult == 1)
                    {
                        response.Message = "The old password entered is invalid";
                    }
                    else
                    {
                        response.Message = "An error occurred when changing the password";
                    }
                }
                else
                {
                    response.Code    = "1"; //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción
                    response.Message = Messages.ApplicationTokenNoAutorize;
                }
            }
            catch (Exception ex)
            {
                response.Code    = "2";
                response.Message = ex.Message;
            }

            response.Donor = donor;

            return(response);
        }
示例#3
0
        public UserResponse ChangePassword([FromBody] UserRequest request)
        {
            UserResponse response = new UserResponse();
            MUser        user     = new MUser();

            BaseRequest baseRequest = new BaseRequest();

            try
            {
                baseRequest.Session = request.Session;

                /*METODO QUE VALIDA EL TOKEN DE APLICACIÓN*/
                if (!BAplication.ValidateAplicationToken(request.ApplicationToken))
                {
                    response.Code    = "2";
                    response.Message = Messages.ApplicationTokenNoAutorize;
                    return(response);
                }
                /*************FIN DEL METODO*************/

                user.UserId   = request.User.UserId;
                user.Password = UEncrypt.Encrypt(UCommon.RandomNumber(1000, 9999).ToString());
                user.Token    = UCommon.GetTokem();

                string Password = user.Password;
                int    Val      = 0;

                BUser.ChangePassword(user, ref Val);

                if (Val.Equals(0))
                {
                    user = BUser.Sel(user, ref Val);

                    response.Code    = "0"; //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción
                    response.Message = Messages.Success;

                    SendEmail(Password, user.User);
                }
                else if (Val.Equals(2))
                {
                    response.Code    = "2"; //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción
                    response.Message = "Failed to change password.";
                }
            }
            catch (Exception ex)
            {
                response.Code    = "2"; //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción
                response.Message = ex.Message;
            }

            response.User = user;

            return(response);
        }
示例#4
0
        public UserResponse LoginUser([FromBody] UserRequest request)
        {
            UserResponse response = new UserResponse();
            MUser        user     = new MUser();

            BaseRequest baseRequest = new BaseRequest();

            try
            {
                baseRequest.Session = request.Session;

                /*METODO QUE VALIDA EL TOKEN DE APLICACIÓN*/
                if (!BAplication.ValidateAplicationToken(request.ApplicationToken))
                {
                    response.Code    = "2";
                    response.Message = Messages.ApplicationTokenNoAutorize;
                    return(response);
                }
                /*************FIN DEL METODO*************/

                user.User     = request.User.User;
                user.Password = UEncrypt.Encrypt(request.User.Password);

                int Val = 0;

                user = BUser.Login(user, ref Val);

                if (Val.Equals(0))
                {
                    response.Code    = "0"; //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción
                    response.Message = Messages.Success;
                }
                else if (Val.Equals(2))
                {
                    response.Code    = "2"; //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción
                    response.Message = String.Format(Messages.ErrorSelect, "User");
                }
                else if (Val.Equals(1))
                {
                    response.Code    = "1"; //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción
                    response.Message = "User does not exist";
                }
            }
            catch (Exception ex)
            {
                response.Code    = "2"; //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción
                response.Message = ex.Message;
            }

            response.User = user;

            return(response);
        }
示例#5
0
        public UserResponse InsertUser([FromBody] UserRequest request)
        {
            UserResponse response = new UserResponse();
            MUser        user     = new MUser();

            try
            {
                BaseRequest baseRequest = new BaseRequest();
                baseRequest.Session = request.Session;

                /*METODO QUE VALIDA EL TOKEN DE APLICACIÓN*/
                if (!BAplication.ValidateAplicationToken(request.ApplicationToken))
                {
                    response.Code    = "2";
                    response.Message = Messages.ApplicationTokenNoAutorize;
                    return(response);
                }
                /*************FIN DEL METODO*************/

                user.Type     = request.User.Type;
                user.User     = request.User.User;
                user.Name     = request.User.Name;
                user.Status   = request.User.Status;
                user.Password = UEncrypt.Encrypt(UCommon.RandomNumber(1000, 9999).ToString());
                user.Token    = UCommon.GetTokem();

                int Val = 0;

                BUser.Insert(user, ref Val);

                if (Val.Equals(0))
                {
                    response.Code    = "0"; //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción
                    response.Message = Messages.Success;

                    SendEmail(user.Password, user.User);
                }
                else if (Val.Equals(2))
                {
                    response.Code    = "2"; //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción
                    response.Message = String.Format(Messages.ErrorInsert, "User");
                }
            }
            catch (Exception ex)
            {
                response.Code    = "2"; //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción
                response.Message = ex.Message;
            }

            response.User = user;

            return(response);
        }
示例#6
0
        public DonorResponse LoginDonor([FromBody] DonorRequest request)
        {
            DonorResponse response    = new DonorResponse();
            MDonor        donor       = new MDonor();
            BaseRequest   baseRequest = new BaseRequest();

            try
            {
                /*METODO QUE VALIDA EL TOKEN DE APLICACIÓN*/
                if (!BAplication.ValidateAplicationToken(request.ApplicationToken))
                {
                    response.Code    = "2";
                    response.Message = Messages.ApplicationTokenNoAutorize;
                    return(response);
                }
                /*************FIN DEL METODO*************/

                //donor.Cellphone = request.Donor.Cellphone; //Se comenta el logeo por Email
                donor.Email    = request.Donor.Email;
                donor.Password = UEncrypt.Encrypt(request.Donor.Password);

                int CodeResult = 0;
                donor = BDonor.Login(donor, ref CodeResult);

                response.Code = CodeResult.ToString(); //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción

                if (CodeResult == 0)
                {
                    response.Message = Messages.Success;
                }
                else if (CodeResult == 1)
                {
                    response.Message = "The session data is invalid.";
                }
                else
                {
                    response.Message = "An error occurred when logging in";
                }
            }
            catch (Exception ex)
            {
                response.Code    = "2";
                response.Message = ex.Message;
            }

            response.Donor = donor;

            return(response);
        }
示例#7
0
        private void SendEmail(string Password, string User)
        {
            MParameter        parameterBE  = new MParameter();
            List <MParameter> parameterBEs = new List <MParameter>();

            int Val = 0;

            parameterBE.Code = "MAIL_PASSUSER";
            parameterBEs     = BParameter.List(parameterBE, ref Val);

            _MAwsEmail.Subject = "UNITLIFE - User generation";
            _MAwsEmail.Message = parameterBEs[0].Valor1.Replace("[Password]", UEncrypt.Decrypt(Password));
            _MAwsEmail.ToEmail = User;

            BAwsSDK.SendEmailAsync(_MAwsEmail);
        }
示例#8
0
        private void SendSES(string Password, string Email)
        {
            int               val          = 0;
            MParameter        parameterBE  = new MParameter();
            List <MParameter> parameterBEs = new List <MParameter>();

            parameterBE.Code = "MAIL_PASS";
            parameterBEs     = BParameter.List(parameterBE, ref val);

            if (val.Equals(0))
            {
                _MAwsEmail.Subject = "UNITLIFE - User generation";
                _MAwsEmail.Message = parameterBEs[0].Valor1.Replace("[Password]", UEncrypt.Decrypt(Password));
                _MAwsEmail.ToEmail = Email;

                BAwsSDK.SendEmailAsync(_MAwsEmail);
            }
        }
示例#9
0
        public static async void SendEmailAsync(MAwsEmail mAwsEmail)
        {
            try
            {
                using (var clients = new AmazonSimpleEmailServiceClient(UEncrypt.Decrypt(mAwsEmail.AccessKey), UEncrypt.Decrypt(mAwsEmail.SecretKey), RegionEndpoint.USWest2))
                {
                    var sendRequest = new SendEmailRequest
                    {
                        Source      = mAwsEmail.VerifiedFromEmail,
                        Destination = new Destination
                        {
                            ToAddresses = new List <string> {
                                mAwsEmail.ToEmail
                            }
                        },
                        Message = new Message
                        {
                            Subject = new Content(mAwsEmail.Subject),
                            Body    = new Body
                            {
                                Html = new Content(mAwsEmail.Message)
                            }
                        },
                    };

                    try
                    {
                        var response = await clients.SendEmailAsync(sendRequest);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            catch (Exception)
            {
            }
        }
示例#10
0
        public static string GetConnectionString()
        {
            var configurationBuilder = new ConfigurationBuilder();
            var path = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json");

            configurationBuilder.AddJsonFile(path, false);

            var root       = configurationBuilder.Build();
            var appSetting = root.GetSection("ConnectionSettings");

            string connectionString = string.Empty;

            var scb = new SqlConnectionStringBuilder();

            scb.InitialCatalog = appSetting["InitialCatalog"];

            scb.DataSource   = UEncrypt.Decrypt(appSetting["DataSource"]);
            scb.UserID       = UEncrypt.Decrypt(appSetting["UserID"]);
            scb.Password     = UEncrypt.Decrypt(appSetting["Password"]);
            connectionString = scb.ToString();

            return(connectionString);
        }
示例#11
0
        public CreateDonorResponse CreateDonor([FromBody] DonorRequest request)
        {
            CreateDonorResponse response = new CreateDonorResponse();
            MDonor      donor            = new MDonor();
            BaseRequest baseRequest      = new BaseRequest();

            try
            {
                /*METODO QUE VALIDA EL TOKEN DE APLICACIÓN*/
                if (!BAplication.ValidateAplicationToken(request.ApplicationToken))
                {
                    response.Code    = "2";
                    response.Message = Messages.ApplicationTokenNoAutorize;
                    return(response);
                }
                /*************FIN DEL METODO*************/

                //donor.Cellphone = request.Donor.Cellphone;
                donor.Email    = request.Donor.Email;
                donor.Password = UEncrypt.Encrypt(UCommon.RandomNumber(1000, 9999).ToString());
                //donor.CountryId = request.Donor.CountryId;
                donor.Token  = UCommon.GetTokem();
                donor.Status = 1;

                baseRequest.Session = request.Session;

                int DonorId = 0;

                int CodeResult = BDonor.Insert(donor, baseRequest, ref DonorId);

                response.Code = CodeResult.ToString(); //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción

                if (CodeResult == 0)
                {
                    response.Message = Messages.Success;
                    //SendSNS(donor.Password, donor.Cellphone, countryBE.Prefix);
                    SendSES(donor.Password, donor.Email);
                }
                else if (CodeResult == 1)
                {
                    if (donor.Registered == 0)
                    {
                        if (BDonor.UpdateCode(donor) == 0)
                        {
                            donor.DonorId = DonorId;

                            response.Code    = "0";
                            response.Message = Messages.Success;
                            //SendSNS(donor.Password, donor.Cellphone, countryBE.Prefix);
                            SendSES(donor.Password, donor.Email);
                        }
                        else
                        {
                            response.Message = String.Format(Messages.ErrorInsert, "Donor");
                        }
                    }
                    else
                    {
                        //response.Message = "The cell phone number and email entered are already used.";
                        response.Message = "The email entered are already used.";
                    }
                }
                else
                {
                    response.Message = String.Format(Messages.ErrorInsert, "Donor");
                }
            }
            catch (Exception ex)
            {
                response.Code    = "2";
                response.Message = ex.Message;
            }

            response.Donor = donor;

            return(response);
        }
示例#12
0
        public CreateDonorResponse ResetPassword([FromBody] DonorRequest request)
        {
            CreateDonorResponse response = new CreateDonorResponse();
            MDonor donor = new MDonor();

            try
            {
                /*METODO QUE VALIDA EL TOKEN DE APLICACIÓN*/
                if (!BAplication.ValidateAplicationToken(request.ApplicationToken))
                {
                    response.Code    = "2";
                    response.Message = Messages.ApplicationTokenNoAutorize;
                    return(response);
                }
                /*************FIN DEL METODO*************/

                donor.Email = request.Donor.Email;

                int refval = 0;

                donor = BDonor.ValidateDonor(donor, ref refval);

                if (refval.Equals(0))
                {
                    donor.Password = UEncrypt.Encrypt(UCommon.RandomNumber(1000, 9999).ToString());
                    donor.Token    = UCommon.GetTokem();

                    MCountry countryBE = new MCountry();
                    countryBE.CountryId = donor.CountryId;
                    countryBE           = BCountry.Select(countryBE, ref refval);

                    if (BDonor.UpdateCode(donor) == 0)
                    {
                        if (!request.Donor.Email.Equals(""))
                        {
                            SendSES(donor.Password, donor.Email);
                        }

                        response.Code    = "0";
                        response.Message = Messages.Success;
                    }
                    else
                    {
                        response.Code    = "2";
                        response.Message = String.Format(Messages.ErrorInsert, "Donor");
                    }
                }
                else
                {
                    donor.Cellphone = request.Donor.Cellphone;
                    donor.Email     = request.Donor.Email;
                    response.Code   = "1";

                    if (!donor.Email.Equals(""))
                    {
                        response.Message = "The email entered is not registered";
                    }
                }
            }
            catch (Exception ex)
            {
                response.Code    = "2";
                response.Message = ex.Message;
            }

            response.Donor = donor;

            return(response);
        }
示例#13
0
        public CreateDonorResponse ValidateDonor([FromBody] DonorRequest request)
        {
            CreateDonorResponse response = new CreateDonorResponse();
            MDonor      donor            = new MDonor();
            BaseRequest baseRequest      = new BaseRequest();

            try
            {
                /*METODO QUE VALIDA EL TOKEN DE APLICACIÓN*/
                if (!BAplication.ValidateAplicationToken(request.ApplicationToken))
                {
                    response.Code    = "2";
                    response.Message = Messages.ApplicationTokenNoAutorize;
                    return(response);
                }
                /*************FIN DEL METODO*************/

                //donor.Cellphone = request.Donor.Cellphone;
                donor.Email    = request.Donor.Email;
                donor.Password = UEncrypt.Encrypt(request.Donor.Password);

                baseRequest.Session = request.Session;

                donor.DonorId = request.Session.UserId;

                if (BSession.ValidateSession(1, baseRequest.Session.Token, baseRequest.Session.UserId).Equals(1))
                {
                    int CodeResult = BDonor.ValidateCode(donor);

                    response.Code = CodeResult.ToString(); //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción

                    if (CodeResult == 0)
                    {
                        response.Message = Messages.Success;
                        SendSESValidate(donor.Email);
                        donor = BDonor.Select(donor, ref CodeResult);
                    }
                    else if (CodeResult == 1)
                    {
                        response.Message = "The code entered is not valid.";
                    }
                    else if (CodeResult == 3)
                    {
                        response.Code    = "1";
                        response.Message = "The Donor is already validated.";
                    }
                    else
                    {
                        response.Message = "The Donor is already validated.";
                    }
                }
                else
                {
                    response.Code    = "1"; //0=> Ëxito | 1=> Validación de Sistema | 2 => Error de Excepción
                    response.Message = Messages.ApplicationTokenNoAutorize;
                }
            }
            catch (Exception ex)
            {
                response.Code    = "2";
                response.Message = ex.Message;
            }

            response.Donor = donor;

            return(response);
        }