public static string PostNewBatchXML(XmlDocument doc)
        {
            User         user      = APIUser.GetUser();
            MemoryStream xmlStream = new MemoryStream();

            doc.Save(xmlStream);
            Byte[] bytes = xmlStream.ToArray();

            string         baseURL        = ConfigurationManager.AppSettings["apiBaseURL"].ToString();
            string         destinationUrl = baseURL + "/BatchStatus/PostFile";
            HttpWebRequest request        = (HttpWebRequest)WebRequest.Create(destinationUrl);

            request.ContentType   = "text/xml; encoding='utf-8'";
            request.ContentLength = bytes.Length;
            request.Method        = "POST";
            request.Timeout       = Timeout.Infinite;
            request.Headers.Add("X-ApiKey", user.ApiAuthToken);
            String username = user.Username;
            String password = CustomEncryptorDecryptor.DecryptPassword(user.Password);
            String encoded  = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));

            request.Headers.Add("Authorization", "Basic " + encoded);
            using (var requestStream = request.GetRequestStream())
            {
                requestStream.Write(bytes, 0, bytes.Length);
            }
            using (var sr = new StreamReader(request.GetResponse().GetResponseStream()))
            {
                string responseStr = sr.ReadToEnd();
                return(responseStr);
            }
        }
Example #2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            User user = IUserService.GetDataByPropertyName(nameof(Utility.User.UniqueKey), key, true, 0, 0, false).FirstOrDefault();

            if (user != null)
            {
                if (txtNewPassword.Text != "" && txtConfirmPassword.Text != "" && txtNewPassword.Text == txtConfirmPassword.Text)
                {
                    string encryptPassword = CustomEncryptorDecryptor.EncryptPassword(txtNewPassword.Text);
                    if (encryptPassword != user.Password)
                    {
                        user.Password        = encryptPassword;
                        user.TransPwd        = encryptPassword;
                        user.UniqueKey       = CustomGenerator.GenerateUniqueKeyForUser(user.Username);
                        user.UpdatedOn       = DateTime.Now;
                        user.UpdatedBy       = user.Id;
                        user.IsPasswordReset = 0;
                        IUserService.UpdateData(user);
                        Response.Redirect("Login.aspx");
                    }
                    else
                    {
                        resetPasswordResponse.InnerHtml = "Please enter new password!";
                    }
                }
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Int32 LoginUserId = 0;

            if (HttpContext.Current.Session["UserId"] != null)
            {
                LoginUserId = Convert.ToInt32(HttpContext.Current.Session["UserId"].ToString());
            }
            if (Session["UserId"] == null)
            {
            }
            else
            {
                Int32 UserId = Convert.ToInt32(Session["UserId"].ToString());
                User  user   = IUserService.GetSingle(UserId);
                if (user != null)
                {
                    if (txtOldPassword.Text != "" && txtNewPassword.Text != "" && txtConfirmPassword.Text != "")
                    {
                        string encryptOldPassword = CustomEncryptorDecryptor.EncryptPassword(txtOldPassword.Text);
                        if (encryptOldPassword == user.Password)
                        {
                            if (txtNewPassword.Text == txtConfirmPassword.Text)
                            {
                                string encryptPassword = CustomEncryptorDecryptor.EncryptPassword(txtNewPassword.Text);
                                if (encryptPassword != user.Password)
                                {
                                    user.Password  = encryptPassword;
                                    user.TransPwd  = encryptPassword;
                                    user.UniqueKey = CustomGenerator.GenerateUniqueKeyForUser(user.Username);
                                    user.UpdatedOn = DateTime.Now;
                                    user.UpdatedBy = LoginUserId;
                                    IUserService.UpdateData(user);
                                    resetPasswordResponse.InnerHtml = "Updated successfully!";
                                }
                                else
                                {
                                    resetPasswordResponse.InnerHtml = "Please enter new password!";
                                }
                            }
                            else
                            {
                                resetPasswordResponse.InnerHtml = "Passwords doesn't match!";
                            }
                        }
                        else
                        {
                            resetPasswordResponse.InnerHtml = "Please enter correct password!";
                        }
                    }
                    else
                    {
                        resetPasswordResponse.InnerHtml = "Please enter all fields!";
                    }
                }
            }
        }
 public static object SubmitClick(string txtOldPassword, string txtNewPassword, string txtConfirmPassword)
 {
     if (HttpContext.Current.Session["UserId"] == null)
     {
         return(null);
     }
     else
     {
         Int32 UserId = Convert.ToInt32(HttpContext.Current.Session["UserId"].ToString());
         User  user   = IUserService.GetSingle(UserId);
         if (user != null)
         {
             if (txtOldPassword != "" && txtNewPassword != "" && txtConfirmPassword != "")
             {
                 string encryptOldPassword = CustomEncryptorDecryptor.EncryptPassword(txtOldPassword);
                 if (encryptOldPassword == user.Password)
                 {
                     if (txtNewPassword == txtConfirmPassword)
                     {
                         string encryptPassword = CustomEncryptorDecryptor.EncryptPassword(txtNewPassword);
                         if (encryptPassword != user.Password)
                         {
                             user.Password  = encryptPassword;
                             user.TransPwd  = encryptPassword;
                             user.UniqueKey = CustomGenerator.GenerateUniqueKeyForUser(user.Username);
                             user.UpdatedOn = DateTime.Now;
                             user.UpdatedBy = UserId;
                             IUserService.UpdateData(user);
                             return("Updated successfully!");
                         }
                         else
                         {
                             return("Please enter new password!");
                         }
                     }
                     else
                     {
                         return("Passwords doesn't match!");
                     }
                 }
                 else
                 {
                     return("Please enter correct password!");
                 }
             }
             else
             {
                 return("Please enter all fields!");
             }
         }
         else
         {
             return("No user!");
         }
     }
 }
Example #5
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            divMessage.Visible = false;
            if (!string.IsNullOrEmpty(txtUsername.Text) && !string.IsNullOrEmpty(txtPassword.Text))
            {
                string        username          = txtUsername.Text;
                string        password          = txtPassword.Text;
                string        encryptedPassword = CustomEncryptorDecryptor.EncryptPassword(password);
                StringBuilder filter            = new StringBuilder();
                filter.Append(" 1=1");
                filter.Append(" and " + Converter.GetColumnNameByPropertyName <User>(nameof(Utility.User.Username)) + " = '" + username + "'");
                filter.Append(" and " + Converter.GetColumnNameByPropertyName <User>(nameof(Utility.User.Password)) + " = '" + encryptedPassword + "'");
                List <User> userMatches = IUserService.GetDataByFilter(filter.ToString(), 0, 0, false);
                if (userMatches.Count > 0)
                {
                    User user = userMatches.FirstOrDefault();
                    filter = new StringBuilder();
                    UserRole userRole = IUserRoleService.GetSingle(user.UserRoleId);
                    UserType userType = IUserTypeService.GetSingle(userRole.UserTypeId);
                    if (userType.Name == "Super Admin" || userType.Name == "Admin")
                    {
                        Session["UserId"]   = user.Id;
                        Session["UserType"] = userType.Name;
                        Session["UserRole"] = userRole.Name;

                        user.LastLoginOn = DateTime.Now;
                        string windowsUsername = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                        //string pcName = Dns.GetHostName();
                        IPHostEntry ip     = Dns.GetHostEntry(Dns.GetHostName());
                        IPAddress[] IPaddr = ip.AddressList;
                        user.LastLoginIp = windowsUsername + ", " + String.Join(", ", IPaddr.Select(x => x.ToString()).ToArray <string>());
                        IUserService.UpdateData(user);

                        Response.Redirect("Default.aspx");
                    }
                }
                else
                {
                    divMessage.Visible   = true;
                    divMessage.InnerHtml = @"<div class='alert alert-block alert-danger fade in'><button data-dismiss='alert' class='close close-sm' type='button'>
                          < i class='fa fa-times'></i></button>
                    <strong>Oh snap!</strong> invalid username or password.</div>";
                }
            }
            else
            {
                divMessage.Visible   = true;
                divMessage.InnerHtml = @"<div class='alert alert-block alert-danger fade in'><button data-dismiss='alert' class='close close-sm' type='button'>
                        <i class='fa fa-times'></i></button>
                    <strong>Oh snap!</strong> Enter Username and Password.</div>";
            }
        }
        public static string PostBatchStatusXMLFile(string postXmlUrl)
        {
            LogWriter logWriter = new LogWriter("ADC Status: " + postXmlUrl);
            User      user      = APIUser.GetUser();

            try
            {
                string         baseURL        = ConfigurationManager.AppSettings["apiBaseURL"].ToString();
                string         postXml        = File.ReadAllText(postXmlUrl);
                string         destinationUrl = baseURL + "/BatchStatus/PostFile";
                HttpWebRequest request        = (HttpWebRequest)WebRequest.Create(destinationUrl);
                byte[]         bytes          = System.Text.Encoding.ASCII.GetBytes(postXml);
                request.ContentType   = "text/xml; encoding='utf-8'";
                request.ContentLength = bytes.Length;
                request.Method        = "POST";
                request.Timeout       = Timeout.Infinite;
                request.Headers.Add("X-ApiKey", user.ApiAuthToken);
                String username = user.Username;
                String password = CustomEncryptorDecryptor.DecryptPassword(user.Password);
                String encoded  = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
                request.Headers.Add("Authorization", "Basic " + encoded);
                using (var requestStream = request.GetRequestStream())
                {
                    requestStream.Write(bytes, 0, bytes.Length);
                }
                using (var response = request.GetResponse())
                {
                    using (var responseStream = response.GetResponseStream())
                    {
                        using (var sr = new StreamReader(responseStream))
                        {
                            string responseStr = sr.ReadToEnd();
                            return(responseStr);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logWriter = new LogWriter("Exception: " + ex.Message);
            }
            return(null);
        }
Example #7
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            string        username          = txtUsername.Text;
            string        password          = txtPassword.Text;
            string        encryptedPassword = CustomEncryptorDecryptor.EncryptPassword(password);
            StringBuilder filter            = new StringBuilder();

            filter.Append(" 1=1");
            filter.Append(" and " + Converter.GetColumnNameByPropertyName <User>(nameof(User.Username)) + "='" + username + "'");
            filter.Append(" and " + Converter.GetColumnNameByPropertyName <User>(nameof(User.Password)) + "='" + encryptedPassword + "'");
            User user = AuthenticationApiCalls.AuthenticateUser(filter.ToString());

            if (user.Username != null)
            {
                APIUser.SetUser(user);
                this.Hide();

                var folderWatcher = new FolderWatcher();
                folderWatcher.Closed += (s, args) => this.Close();
                folderWatcher.Show();

                var mainForm = new MainForm();
                mainForm.Closed += (s, args) => this.Close();
                mainForm.Show();

                //var fileWatcher = new FileWatcher();
                //fileWatcher.Closed += (s, args) => this.Close();
                //fileWatcher.Show();
            }
            else if (user.IsOnline == 0 && user.UniqueKey != null)
            {
                txtPassword.Text = "";
                MetroMessageBox.Show(this, user.UniqueKey, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                txtPassword.Text = "";
                MetroMessageBox.Show(this, "Not Valid! Please try again.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #8
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUsername.Text != "" && txtPassword.Text != "")
            {
                string        username          = txtUsername.Text;
                string        password          = txtPassword.Text;
                string        encryptedPassword = CustomEncryptorDecryptor.EncryptPassword(password);
                StringBuilder filter            = new StringBuilder();
                filter.Append(" 1=1");
                filter.Append(" and " + Converter.GetColumnNameByPropertyName <User>(nameof(Utility.User.Username)) + " = '" + username + "'");
                filter.Append(" and " + Converter.GetColumnNameByPropertyName <User>(nameof(Utility.User.Password)) + " = '" + encryptedPassword + "'");
                List <User> userMatches = IUserService.GetDataByFilter(filter.ToString(), 0, 0, false);
                if (userMatches.Count > 0)
                {
                    User user = userMatches.FirstOrDefault();
                    filter = new StringBuilder();
                    UserRole userRole = IUserRoleService.GetSingle(user.UserRoleId);
                    UserType userType = IUserTypeService.GetSingle(userRole.UserTypeId);
                    if (userType.Name == "Super Admin" || userType.Name == "Admin")
                    {
                        Session["UserId"]   = user.Id;
                        Session["UserType"] = userType.Name;
                        Session["UserRole"] = userRole.Name;

                        user.LastLoginOn = DateTime.Now;
                        string windowsUsername = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                        //string pcName = Dns.GetHostName();
                        IPHostEntry ip     = Dns.GetHostEntry(Dns.GetHostName());
                        IPAddress[] IPaddr = ip.AddressList;
                        user.LastLoginIp = windowsUsername + ", " + String.Join(", ", IPaddr.Select(x => x.ToString()).ToArray <string>());
                        IUserService.UpdateData(user);

                        Response.Redirect("Default.aspx");
                    }
                }
            }
        }
Example #9
0
        public static object Add(User obj)
        {
            Response response = new Response();

            if (obj.UserRoleId == 0)
            {
                response.isSuccess = false;
                response.message   = "Selct the Role";
                return(response);
            }
            else if (obj.UserRoleId == 5 && obj.BranchId == 0)
            {
                response.isSuccess = false;
                response.message   = "Select the Branch";
                return(response);
            }
            if (obj.Username == "")
            {
                response.isSuccess = false;
                response.message   = "Username cannot be empty";
                return(response);
            }
            if (obj.EmailId == "")
            {
                response.isSuccess = false;
                response.message   = "Email cannot be empty";
                return(response);
            }
            if (obj.MobileNumber == "")
            {
                response.isSuccess = false;
                response.message   = "Mobile number cannot be empty";
                return(response);
            }
            else
            {
                response = IsValidPhoneNumber(obj.MobileNumber);
                if (!response.isSuccess)
                {
                    return(response);
                }
            }
            Int32 LoginUserId = 0;

            if (HttpContext.Current.Session["UserId"] != null)
            {
                LoginUserId = Convert.ToInt32(HttpContext.Current.Session["UserId"].ToString());
            }
            try
            {
                if (obj.Id == 0)
                {
                    if (obj.Username != "")
                    {
                        List <User> userMatches = IUserService.GetDataByPropertyName(nameof(Utility.User.Username), obj.Username, true, 0, 0, false);
                        if (userMatches.Count > 0)
                        {
                            response.isSuccess = false;
                            response.message   = "Username is taken";
                            return(response);
                        }
                        List <User> emailMatches = IUserService.GetDataByPropertyName(nameof(Utility.User.EmailId), obj.EmailId, true, 0, 0, false);
                        if (emailMatches.Count > 0)
                        {
                            response.isSuccess = false;
                            response.message   = "Email already exist";
                            return(response);
                        }
                    }
                    string defaultPassword = CustomEncryptorDecryptor.EncryptPassword("default123");
                    obj.UniqueKey    = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    obj.Password     = defaultPassword;
                    obj.TransPwd     = defaultPassword;
                    obj.ApiAuthToken = TokenGenerator.Get(obj.Username);
                    obj.CreatedBy    = LoginUserId;
                    obj.CreatedOn    = DateTime.Now;
                    User   user    = obj;
                    string siteURL = ConfigurationManager.AppSettings["siteURL"];
                    if (obj.UserRoleId == 5 && user.BranchId != 0)
                    {
                        Branch b = IBranchService.GetSingle(user.BranchId);
                        user.TransPwd = b.Code;
                    }
                    else if (obj.UserRoleId == 4)
                    {
                        user.TransPwd = "Regional Admin";
                    }
                    else if (obj.UserRoleId == 3)
                    {
                        user.TransPwd = "HQ";
                    }
                    else
                    {
                        user.TransPwd = "";
                    }

                    Email email = new Email()
                    {
                        Subject = "User created - GHB",
                        Link    = siteURL + "Login.aspx",
                        User    = user
                    };
                    response = EmailService.SendActivationMail(email);
                    if (response.isSuccess)
                    {
                        user = IUserService.PostData(obj);
                        response.isSuccess = true;
                        response.message   = "Success";
                    }
                    else
                    {
                        return(response);
                    }
                }
                else
                {
                    User user = IUserService.GetSingle(obj.Id);
                    obj.CreatedBy   = user.CreatedBy;
                    obj.CreatedOn   = user.CreatedOn;
                    obj.LastLoginOn = user.LastLoginOn;
                    obj.UpdatedOn   = DateTime.Now;
                    obj.UpdatedBy   = LoginUserId;
                    IUserService.UpdateData(obj);

                    response.isSuccess = true;
                    response.message   = "Success";
                }
                return(response);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Add admin action: " + ex.Message);
                response.isSuccess = false;
                response.message   = ex.Message;
                return(response);
            }
        }
        //public async static Task<int> PostFileAsync(string postUrl, HttpClient httpClient)
        //{
        //    MultipartFormDataContent form = new MultipartFormDataContent();
        //    FileStream fs = File.OpenRead(postUrl);
        //    var streamContent = new StreamContent(fs);

        //    var imageContent = new ByteArrayContent(streamContent.ReadAsByteArrayAsync().Result);
        //    imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");

        //    form.Add(imageContent, "image", Path.GetFileName(postUrl));
        //    var response = httpClient.PostAsync(url, form).Result;

        //    return 0;
        //}
        public async static Task <string> PostAllFiles(string file)
        {
            LogWriter logWriter             = new LogWriter("Post All Files: " + file);
            User      user                  = APIUser.GetUser();
            string    fileExtension         = Path.GetExtension(file);
            string    fileNameWithExtension = Path.GetFileName(file);
            //string fileName = Path.GetFileNameWithoutExtension(file);
            string fileName = Path.GetFileNameWithoutExtension(file);

            string[]      splitFileName         = fileName.Split('_');
            int           filesSuccessfullCount = 0;
            List <string> filesSuccessfull      = new List <string>();
            int           filesCount            = 0;

            try
            {
                if (fileExtension.ToLower() == ".xml")
                {
                    string   commonFileName = String.Join("_", splitFileName.ToList <string>().Take(3).ToArray());
                    string[] matchedFiles   = Directory.GetFiles(SplitFromADC, commonFileName + "*");
                    if (matchedFiles.ToList().Count - 1 == Convert.ToInt32(splitFileName.ToList().Last().ToString()))
                    {
                        filesCount = matchedFiles.Count();
                        foreach (string matchFile in matchedFiles)
                        {
                            //fileNameWithExtension = Path.GetFileName(matchFile);
                            logWriter = new LogWriter("Post All Files matchFile: " + matchFile);
                            string FileName  = Path.GetFileName(matchFile);
                            bool   isSuccess = false;
                            while (!isSuccess)
                            {
                                string baseURL = ConfigurationManager.AppSettings["apiBaseURL"].ToString();
                                //string postImage = System.IO.File.ReadAllText(postImageUrl);
                                string destinationUrl = baseURL + "/FileTransmission/PostFile";
                                byte[] bytes          = System.IO.File.ReadAllBytes(matchFile);
                                //string fileExtension = Path.GetExtension(matchFile);
                                string         mimeType = MimeMapping.MimeUtility.GetMimeMapping(matchFile);
                                HttpWebRequest request  = (HttpWebRequest)WebRequest.Create(destinationUrl);
                                request.Headers.Add("FileName", FileName);
                                request.ContentType   = mimeType + "; encoding='utf-8'";
                                request.ContentLength = bytes.Length;
                                request.Method        = "POST";
                                request.Timeout       = Timeout.Infinite;
                                request.Headers.Add("X-ApiKey", user.ApiAuthToken);
                                String username = user.Username;
                                String password = CustomEncryptorDecryptor.DecryptPassword(user.Password);
                                String encoded  = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
                                request.Headers.Add("Authorization", "Basic " + encoded);
                                request.UseDefaultCredentials = true;

                                request.PreAuthenticate = true;

                                request.Credentials = CredentialCache.DefaultCredentials;
                                //var task = request.GetRequestStreamAsync();
                                logWriter = new LogWriter("Post All Files While: " + file);
                                try
                                {
                                    using (var requestStream = await request.GetRequestStreamAsync())
                                    {
                                        requestStream.Write(bytes, 0, bytes.Length);
                                    }

                                    using (var response = request.GetResponse())
                                    {
                                        using (var responseStream = response.GetResponseStream())
                                        {
                                            using (var sr = new StreamReader(responseStream))
                                            {
                                                string responseStr = sr.ReadToEnd();
                                                //if (File.Exists(SplitFromADCArchive + fileName))
                                                //    File.Delete(SplitFromADCArchive + fileName);
                                                //File.Move(matchFile, SplitFromADCArchive + fileName);
                                                filesSuccessfullCount++;
                                                filesSuccessfull.Add(matchFile);
                                                isSuccess = true;
                                                //return splitFileName[0];
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    isSuccess = false;
                                    logWriter = new LogWriter("Post All Files While Exception: " + ex.Message);
                                }
                            }
                            //Task<string> task = TransmissionApiCalls.PostFile(matchFile);
                            //TaskList.Add(task);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logWriter = new LogWriter("Postc All Files File: " + file);
                logWriter = new LogWriter("Post All Files Exception: " + ex.Message);
                return(null);
            }

            if (filesSuccessfullCount == filesCount)
            {
                foreach (string successFile in filesSuccessfull)
                {
                    string successFileName = Path.GetFileName(successFile);
                    if (File.Exists(SplitFromADCArchive + successFile))
                    {
                        File.Delete(SplitFromADCArchive + successFile);
                    }
                    File.Move(successFile, SplitFromADCArchive + successFileName);
                }
                return(splitFileName[0]);
            }
            //else
            //{
            //    foreach(string successFile in filesSuccessfull)
            //    {
            //        if (File.Exists(SplitFromADCArchive + fileName))
            //            File.Delete(SplitFromADCArchive + fileName);
            //        File.Move(successFile, SplitFromADCArchive + fileName);
            //    }
            //}

            return(null);
        }
        public async static Task <string> PostFile(string postUrl)
        {
            LogWriter logWriter = new LogWriter(postUrl);
            User      user      = APIUser.GetUser();

            try
            {
                string FileName = Path.GetFileName(postUrl);
                string baseURL  = ConfigurationManager.AppSettings["apiBaseURL"].ToString();
                //string postImage = System.IO.File.ReadAllText(postImageUrl);
                string         destinationUrl = baseURL + "/FileTransmission/PostFile";
                byte[]         bytes          = System.IO.File.ReadAllBytes(postUrl);
                string         fileExtension  = Path.GetExtension(postUrl);
                string         mimeType       = MimeMapping.MimeUtility.GetMimeMapping(postUrl);
                HttpWebRequest request        = (HttpWebRequest)WebRequest.Create(destinationUrl);
                request.Headers.Add("FileName", FileName);
                request.ContentType   = mimeType + "; encoding='utf-8'";
                request.ContentLength = bytes.Length;
                request.Method        = "POST";
                request.Timeout       = Timeout.Infinite;
                request.Headers.Add("X-ApiKey", user.ApiAuthToken);
                String username = user.Username;
                String password = CustomEncryptorDecryptor.DecryptPassword(user.Password);
                String encoded  = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
                request.Headers.Add("Authorization", "Basic " + encoded);
                request.UseDefaultCredentials = true;

                request.PreAuthenticate = true;

                request.Credentials = CredentialCache.DefaultCredentials;
                logWriter           = new LogWriter("User: "******" : " + password);
                logWriter           = new LogWriter("Authorization: " + "Basic " + encoded);
                //var task = request.GetRequestStreamAsync();
                using (var requestStream = await request.GetRequestStreamAsync())
                {
                    requestStream.Write(bytes, 0, bytes.Length);
                }
                using (var sr = new StreamReader(request.GetResponse().GetResponseStream()))
                {
                    string   responseStr   = sr.ReadToEnd();
                    string[] splitFileName = FileName.Split('_');

                    string fileName = Path.GetFileName(postUrl);

                    if (File.Exists(SplitFromADCArchive + fileName))
                    {
                        File.Delete(SplitFromADCArchive + fileName);
                    }
                    File.Move(postUrl, SplitFromADCArchive + fileName);

                    return(splitFileName[0]);
                }
            }
            catch (WebException webex)
            {
                logWriter = new LogWriter("Exception: " + postUrl + " : " + webex.Message);
                WebResponse errResp = webex.Response;
                using (Stream respStream = errResp.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(respStream);
                    string       text   = reader.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                logWriter = new LogWriter("Exception: " + postUrl + " : " + ex.Message);
            }
            return(null);
        }
Example #12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserId"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            Int32 LoginUserId = 0;

            if (HttpContext.Current.Session["UserId"] != null)
            {
                LoginUserId = Convert.ToInt32(HttpContext.Current.Session["UserId"].ToString());
            }
            string isSubmit = Request.QueryString["isSubmit"];

            if (isSubmit != null)
            {
                if (isSubmit.ToString() == "1")
                {
                    string oldPassword = Request.QueryString["txtOldPassword"].ToString();
                    txtOldPassword.Text = oldPassword;
                    string newPassword = Request.QueryString["txtNewPassword"].ToString();
                    txtNewPassword.Text = newPassword;
                    string confirmPassword = Request.QueryString["txtConfirmPassword"].ToString();
                    txtConfirmPassword.Text = confirmPassword;
                    if (txtOldPassword.Text != "" && txtNewPassword.Text != "" && txtConfirmPassword.Text != "")
                    {
                        Int32 UserId = Convert.ToInt32(HttpContext.Current.Session["UserId"].ToString());
                        User  user   = IUserService.GetSingle(UserId);
                        if (user != null)
                        {
                            string encryptOldPassword = CustomEncryptorDecryptor.EncryptPassword(txtOldPassword.Text);
                            if (encryptOldPassword == user.Password)
                            {
                                if (txtNewPassword.Text == txtConfirmPassword.Text)
                                {
                                    string encryptPassword = CustomEncryptorDecryptor.EncryptPassword(txtNewPassword.Text);
                                    if (encryptPassword != user.Password)
                                    {
                                        user.Password  = encryptPassword;
                                        user.TransPwd  = encryptPassword;
                                        user.UniqueKey = CustomGenerator.GenerateUniqueKeyForUser(user.Username);
                                        user.UpdatedOn = DateTime.Now;
                                        user.UpdatedBy = LoginUserId;
                                        IUserService.UpdateData(user);
                                        resetPasswordResponse.InnerHtml = "Updated successfully!";
                                    }
                                    else
                                    {
                                        resetPasswordResponse.InnerHtml = "Please enter new password!";
                                    }
                                }
                                else
                                {
                                    resetPasswordResponse.InnerHtml = "Passwords doesn't match!";
                                }
                            }
                            else
                            {
                                resetPasswordResponse.InnerHtml = "Please enter correct password!";
                            }
                        }
                        else
                        {
                            resetPasswordResponse.InnerHtml = "No user!";
                        }
                    }
                }
            }
        }