//[ValidateAntiForgeryToken]
        public IActionResult ValidateAnchorCompanyLogOn(string Email, string Password)
        {
            if (!ReCaptchaPassed(
                    Request.Form["g-recaptcha-response"], // that's how you get it from the Request object
                    _configuration.GetSection("GoogleReCaptcha:SecretKey").Value
                    ))
            {
                TempData["InvalidCredential"] = "Captcha verification failed.";
                return(RedirectToAction("AnchorCompanyLogin", "Account"));
            }
            string ActionName     = this.ControllerContext.RouteData.Values["action"].ToString();
            string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            Int32? UserLoginID    = HttpContext.Session.GetInt32("UserID");
            string ErrorMessage   = string.Empty;

            try
            {
                Password = SecurityHelperService.Encrypt(Password);
                User userdata = _userRepository.FindUserName(Email, Password);
                HttpContext.Session.SetString("Role", "InternalUser");


                CookieOptions option = new CookieOptions();
                option.Expires = DateTime.Now.AddDays(2);
                Response.Cookies.Append("RoleAccess", "Anchor Company", option);

                if (userdata == null)
                {
                    ViewBag.InvalidCredential = "Enter valid credential";
                    return(View("AnchorCompanyLogin"));
                }
                else
                {
                    var UserID   = userdata.UserID;
                    var UserName = userdata.Name;
                    HttpContext.Session.SetInt32("UserID", UserID);
                    HttpContext.Session.SetString("UserName", UserName);
                    HttpContext.Session.SetString("JWToken", GenerateJWTToken(UserName));
                    SetCookie(UserID.ToString(), UserName, "InternalUser");
                    return(RedirectToAction("InvoiceList", "Invoice"));
                }
            }
            catch (Exception ex)
            {
                var st        = new StackTrace(ex, true);
                var frame     = st.GetFrame(0);
                int ErrorLine = frame.GetFileLineNumber();
                var Result    = _CommonRepository.LogManagement(ControllerName, ActionName, ex.Message, ErrorLine, UserLoginID);
                return(RedirectToAction("ErrorPage", "Common"));
            }
        }
        public ActionResult SubmitPassword(string Username, string Role, string NewPassword)
        {
            var Result = _CommonRepository.UpdatePassword(SecurityHelperService.Encrypt(NewPassword), Username, Role);

            if (Role == "SuperAdmin")
            {
                return(RedirectToAction("SuperAdminLogin", "Account"));
            }
            else if (Role == "MasterAdmin")
            {
                return(RedirectToAction("AdminLogin", "Account"));
            }
            else
            {
                return(RedirectToAction("UserLogin", "Account")); //(Role == "Vendor" || Role == "Bank" || Role == "Anchor")
            }
        }
 /// <summary>
 /// set the cookie
 /// </summary>
 /// <param name="key">key (unique indentifier)</param>
 /// <param name="value">value to store in cookie object</param>
 /// <param name="expireTime">expiration time</param>
 private void SetCookie(string UserID, string UserName, string UserRole)
 {
     try
     {
         if (Convert.ToString(Request.Cookies.ContainsKey("UserID")) == "False")
         {
             var option = new CookieOptions();
             option.Expires = DateTime.Now.AddDays(1);
             Response.Cookies.Append("UserID", SecurityHelperService.Encrypt(UserID), option);
             Response.Cookies.Append("LoginName", SecurityHelperService.Encrypt(UserName), option);
             Response.Cookies.Append("Role", SecurityHelperService.Encrypt(UserRole), option);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #4
0
 /// <summary>
 /// Set cookie method
 /// </summary>
 /// <param name="UserID"></param>
 /// <param name="UserName"></param>
 /// <param name="UserRole"></param>
 public void SetCookie(string UserID, string UserName, string UserRole)
 {
     try
     {
         if (Convert.ToString(Request.Cookies.ContainsKey("UserID")) == null)
         {
             var option = new CookieOptions();
             option.Expires = DateTime.Now.AddMinutes(10);
             Response.Cookies.Append("UserID", UserID, option);
             Response.Cookies.Append("UserName", SecurityHelperService.Encrypt(UserName), option);
             Response.Cookies.Append("Role", SecurityHelperService.Encrypt(UserRole), option);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #5
0
        //private readonly IHostingEnvironment _hostingEnvironment;

        //public UploadExcelDetails()
        //{

        //}
        //public UploadExcelDetails(IHostingEnvironment hostingEnvironment)
        //{
        //    _hostingEnvironment = hostingEnvironment;
        //}

        public void UploadVendors(string Path, Int64?CompanyID, string FileName, string CompanyName)
        {
            try
            {
                DataTable dt             = new DataTable();
                string    JSONString     = string.Empty;
                var       memory         = new MemoryStream();
                string    sFileExtension = FileName.Split('.')[1];
                //    var FileName = CompanyName + DateTime.Now.ToString("yyyyMMddhhmmss");
                ISheet sheet;
                //string fullPath = Path.Combine(FileName + sFileExtension);
                using (var stream = new FileStream(Path, FileMode.Open))
                {
                    stream.CopyTo(memory);
                    memory.Position = 0;
                    if (sFileExtension == ".xls")
                    {
                        HSSFWorkbook hssfwb = new HSSFWorkbook(memory); //This will read the Excel 97-2000 formats
                        sheet = hssfwb.GetSheetAt(0);                   //get first sheet from workbook
                    }
                    else
                    {
                        XSSFWorkbook hssfwb = new XSSFWorkbook(memory); //This will read 2007 Excel format
                        sheet = hssfwb.GetSheetAt(0);                   //get first sheet from workbook
                    }

                    IRow headerRow = sheet.GetRow(0); //Get Header Row
                    int  cellCount = headerRow.LastCellNum;
                    for (int j = 0; j < cellCount; j++)
                    {
                        NPOI.SS.UserModel.ICell cell = headerRow.GetCell(j);
                        if (cell == null || string.IsNullOrWhiteSpace(cell.ToString()))
                        {
                            continue;
                        }
                        dt.Columns.Add(headerRow.GetCell(j).ToString());
                    }
                    dt.Columns.Add("Message");

                    for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++) //Read Excel File
                    {
                        DataRow dr  = dt.NewRow();
                        IRow    row = sheet.GetRow(i);
                        if (row == null)
                        {
                            continue;
                        }
                        if (row.Cells.All(d => d.CellType == CellType.Blank))
                        {
                            continue;
                        }
                        for (int j = row.FirstCellNum; j < cellCount; j++)
                        {
                            if (row.GetCell(j) != null)
                            {
                                dr[j] = row.GetCell(j).ToString();
                            }
                        }

                        dt.Rows.Add(dr);

                        if (dt.Rows[i - 1]["Vendor Name"].ToString() != "" && dt.Rows[i - 1]["Pan Number"].ToString() != "" && dt.Rows[i - 1]["Contact Person Name"].ToString() != "" && dt.Rows[i - 1]["Email ID"].ToString() != "" && dt.Rows[i - 1]["Contact Number"].ToString() != "")
                        {
                            if (!Regex.IsMatch(dt.Rows[i - 1]["Pan Number"].ToString(), @"^[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}$"))
                            {
                                dt.Rows[i - 1]["Message"] = "Pan Number is not valid";
                                continue;
                            }
                            if (dt.Rows[i - 1]["MSME  (Yes/No)"].ToString().ToLower() != "")
                            {
                                if (dt.Rows[i - 1]["MSME  (Yes/No)"].ToString().ToLower() == "yes")
                                {
                                    if (dt.Rows[i - 1]["UAM Number"].ToString() == "")
                                    {
                                        dt.Rows[i - 1]["Message"] = "UAM Number should not be blank";
                                        continue;
                                    }
                                }
                            }
                            if (dt.Rows[i - 1]["UAM Number"].ToString() != "")
                            {
                                if (dt.Rows[i - 1]["MSME  (Yes/No)"].ToString().ToLower() == "")
                                {
                                    dt.Rows[i - 1]["Message"] = "MSME should not be blank";
                                    continue;
                                }
                            }
                            if (!Regex.IsMatch(dt.Rows[i - 1]["Email ID"].ToString(), @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"))
                            {
                                dt.Rows[i - 1]["Message"] = "Email ID is not valid";
                                continue;
                            }

                            else
                            {
                                dt.Rows[i - 1]["Message"] = "Success";
                            }
                        }
                        else
                        {
                            if (dt.Rows[i - 1]["Vendor Name"].ToString() == "")
                            {
                                dt.Rows[i - 1]["Message"] = "Vendor Name should not be blank";
                                continue;
                            }
                            if (dt.Rows[i - 1]["Pan Number"].ToString() == "")
                            {
                                dt.Rows[i - 1]["Message"] = "Pan Number should not be blank";
                                continue;
                            }
                            if (dt.Rows[i - 1]["Contact Person Name"].ToString() == "")
                            {
                                dt.Rows[i - 1]["Message"] = "Contact Person Name should not be blank";
                                continue;
                            }
                            if (dt.Rows[i - 1]["Email ID"].ToString() == "")
                            {
                                dt.Rows[i - 1]["Message"] = "Email ID should not be blank";
                                continue;
                            }
                            if (dt.Rows[i - 1]["Contact Number"].ToString() == "")
                            {
                                dt.Rows[i - 1]["Message"] = "Contact Number should not be blank";
                                continue;
                            }
                        }

                        string randomPassword = GeneratePassword();
                        string Password       = SecurityHelperService.Encrypt(randomPassword);
                        var    Result         = InsertVendorRecord(dr, CompanyID, Password);

                        if (Convert.ToInt32(Result.Value) > 0)
                        {
                            //string Template = string.Empty;
                            string Template = GetVendorRegisterMailTemplate();
                            string path     = Template;
                            string EMAIL_TOKEN_PAYMENT_LINK = "##$$PAYMENT_LINK$$##";
                            string paymentLink = "http://dotnet.brainvire.com/Finocart/Account/AdminLogin";///change url
                            //string MailStatus = string.Empty;
                            string    emailToAddress = dr[6].ToString();
                            string    subject        = "Vendor registration";
                            WebClient client         = new WebClient();
                            string    startupPath    = Environment.CurrentDirectory;

                            string body = path;
                            // string body = client.DownloadString(startupPath + "/Views/Template/EmailTemplate.cshtml");
                            body = body.Replace("@@User@@", dr[0].ToString());
                            body = body.Replace("@@PanNumber@@", dr[1].ToString());
                            body = body.Replace("@@ProjectName@@", "Finocart");
                            body = body.Replace("@@VendorName@@", dt.Rows[i - 1]["Vendor Name"].ToString());
                            body = body.Replace("@@AnchorCompanyname@@", CompanyName);
                            body = body.Replace(EMAIL_TOKEN_PAYMENT_LINK, paymentLink);
                            body = body.Replace("@@PanNumber@@", dt.Rows[i - 1]["Pan Number"].ToString());
                            body = body.Replace("@@Password@@", randomPassword);
                            IEnumerable <LookupDetail> lookupDetails = getLookupDetailByKey("SMTPInfo");
                            SendEmail(lookupDetails, emailToAddress, subject, body, true);
                        }

                        if (Convert.ToInt32(Result.Value) == -1)
                        {
                            dt.Rows[i - 1]["Message"] = "Pan Number already exists";
                            continue;
                        }
                    }
                    //GetLog(dt);
                }
                //}

                JSONString = JsonConvert.SerializeObject(dt);
                GetLog(JSONString, "Vendor", CompanyID, CompanyName, FileName);
                //HttpContext.Session.SetString("Excel", JSONString);
                //return Json(new { result = dt });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult SendForgetPasswordMail(ForgetPasswordModel objForgetPassword)
        {
            string             ActionName     = this.ControllerContext.RouteData.Values["action"].ToString();
            string             ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            Int32?             UserID         = HttpContext.Session.GetInt32("UserID");
            string             ErrorMessage   = string.Empty;
            var                RoleName       = "";
            FinocartMaster     objDatawithSP1 = null;
            Company            objDatawithSP2 = null;
            User               objDatawithSP3 = null;
            IEnumerable <User> objDatawithSP  = _CommonRepository.CheckUserPassword();
            IEnumerable <User> objDatawithSP4 = _CommonRepository.CheckUserPassword();

            try
            {
                var    Name = "";
                string ID   = "";

                string randomPassword = _CommonRepository.GeneratePassword();
                // string EncryptToken = SecurityHelperService.Encrypt(Token);
                string EmailID = objForgetPassword.EmailID.Trim();
                var    data    = Encoding.UTF8.GetBytes(objForgetPassword.RoleName);
                RoleName = Convert.ToBase64String(data);
                if (objForgetPassword.RoleName == "MasterAdmin")
                {
                    //IEnumerable<Company> objDatawithSP = _CommonRepository.CheckAdminPassword();
                    //objDatawithSP = objDatawithSP.Where(x => x.Contact_email == EmailID && x.IsDelete == false);
                    objDatawithSP2 = _CommonRepository.CheckAdminByEmailExists(EmailID);
                    if (objDatawithSP2 != null && (!objDatawithSP2.IsDelete || objDatawithSP2.LoginAttempt == 3))
                    {
                        Name = objDatawithSP2.Company_name;
                        ID   = Convert.ToString(objDatawithSP2.CompanyID);
                    }
                }
                if (objForgetPassword.RoleName == "InternalUser")
                {
                    //IEnumerable<User> objDatawithSP = _CommonRepository.CheckUserPassword();
                    //objDatawithSP = objDatawithSP.Where(x => x.Email == EmailID && x.IsDelete == true);
                    objDatawithSP3 = _CommonRepository.CheckUserByEmail(EmailID, true);
                    if (objDatawithSP3 != null)
                    {
                        Name = objDatawithSP3.Name;
                        ID   = Convert.ToString(objDatawithSP3.UserID);
                    }
                }
                if (objForgetPassword.RoleName == "Vendor")
                {
                    objDatawithSP = objDatawithSP.Where(x => x.Email == EmailID);
                    if (objDatawithSP.Any())
                    {
                        Name = objDatawithSP.ElementAt(0).Name;
                        ID   = Convert.ToString(objDatawithSP.ElementAt(0).UserID);
                    }
                }

                if (objForgetPassword.RoleName == "Anchor Company")
                {
                    objDatawithSP4 = objDatawithSP.Where(x => x.Email == EmailID && x.IsDelete == false);
                    if (objDatawithSP4.Any())
                    {
                        Name = objDatawithSP4.ElementAt(0).Name;
                        ID   = Convert.ToString(objDatawithSP4.ElementAt(0).UserID);
                    }
                }
                if (objForgetPassword.RoleName == "SuperAdmin")
                {
                    objDatawithSP1 = _CommonRepository.CheckSuperAdminByEmail(EmailID, false);
                    if (objDatawithSP1 != null)
                    {
                        Name = objDatawithSP1.Name;
                        ID   = Convert.ToString(objDatawithSP1.ID);
                    }
                }

                if (Name != "")
                {
                    string Token = ID + "~" + objForgetPassword.RoleName + "~" + DateTime.Now;

                    string EncryptToken = SecurityHelperService.Encrypt(Token);
                    // var Result = _CommonRepository.UpdatePassword(Password, EmailID, objForgetPassword.RoleName);
                    // if (Result > 0)
                    //{

                    IEnumerable <GetForgetPasswordMailTemplate> lstAwaitedInvVendorsView = _lookUpRepository.getForgetPasswordMailTemplate();
                    string path = lstAwaitedInvVendorsView.ElementAt(0).Template;
                    string EMAIL_TOKEN_PAYMENT_LINK = "##$$LOGIN_LINK$$##";
                    //string paymentLink ="http://*****:*****@@User@@", Name);
                    body = body.Replace("@@ProjectName@@", "Finocart");
                    body = body.Replace(EMAIL_TOKEN_PAYMENT_LINK, paymentLink);
                    body = body.Replace("http://dotnet.brainvire.com/Finocart/Account/AdminLogin", paymentLink);
                    body = body.Replace("@@Password@@", randomPassword);
                    IEnumerable <LookupDetails> lookupDetails = _lookUpRepository.getLookupDetailByKey("SMTPInfo");
                    _CommonRepository.SendEmail(lookupDetails, emailToAddress, subject, body, true);
                    TempData["MailSuccess"] = "Mail sent successfully";
                    // }
                }
                else
                {
                    TempData["WrongMail"] = "Email ID is not valid";
                }
            }
            catch (Exception ex)
            {
                TempData["FailureMessage"] = "We are sorry, something went wrong. Please try again later";
                var st        = new StackTrace(ex, true);
                var frame     = st.GetFrame(0);
                int ErrorLine = frame.GetFileLineNumber();
                var Result    = _CommonRepository.LogManagement(ControllerName, ActionName, ex.Message, ErrorLine, UserID);
                return(RedirectToAction("ErrorPage", "Common"));
            }

            return(RedirectToAction("ForgetPassword", "Account", new { Role = RoleName }));
        }
        public IActionResult ValidateAdminLogOn(string PANNumber, string Password, string IsRemember)
        {
            if (!ReCaptchaPassed(
                    Request.Form["g-recaptcha-response"], // that's how you get it from the Request object
                    _configuration.GetSection("GoogleReCaptcha:SecretKey").Value
                    ))
            {
                TempData["InvalidCredential"] = "Captcha verification failed.";
                return(RedirectToAction("AdminLogin", "Account"));
            }

            string pw = SecurityHelperService.Decrypt("9b1L+4cRvb5EYXkEw8dl3bgkBFnKqjSQ");

            string InputCredential = PANNumber;
            string Controller      = "";
            string ActionName      = "";

            Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
            Match match = regex.Match(InputCredential);

            Password = SecurityHelperService.Encrypt(Password);
            AdminLoginModel objDatawithSP = _adminRepository.FindName(PANNumber, Password);

            if (objDatawithSP == null)
            {
                string strLockRes = _adminRepository.LockedAdminUser(PANNumber);
                TempData["InvalidCredential"] = strLockRes;
                return(RedirectToAction("AdminLogin", "Account"));
            }
            else
            {
                var AdminID      = objDatawithSP.CompanyID;
                var AdminName    = objDatawithSP.ContactPersonName;
                var InternalRole = objDatawithSP.Role;
                var companyname  = objDatawithSP.Name;

                CookieOptions option = new CookieOptions();
                option.Expires = DateTime.Now.AddDays(2);
                Response.Cookies.Append("RoleAccess", "AdminLogin", option);


                TempData["InternalRole"] = InternalRole;
                HttpContext.Session.SetInt32("UserID", AdminID);
                HttpContext.Session.SetString("LoginName", AdminName);
                HttpContext.Session.SetString("Role", "MasterAdmin");
                HttpContext.Session.SetString("CompanyType", InternalRole);
                HttpContext.Session.SetString("Companyname", companyname);
                HttpContext.Session.SetString("JWToken", GenerateJWTToken(AdminName));
                //HttpContext.Session.SetString("RoleAccess", RoleAccess);
                if (objDatawithSP.IsTemporaryPassword == false)
                {
                    TempData["Role"] = "MasterAdmin";

                    if (IsRemember == "1")
                    {
                        SetCookie(AdminID.ToString(), AdminName, "MasterAdmin");
                        Response.Cookies.Append("PANNumber", PANNumber, option);
                    }
                    return(RedirectToAction("UserList", "User"));
                }
                else
                {
                    var data = Encoding.UTF8.GetBytes("MasterAdmin");
                    var Role = Convert.ToBase64String(data);
                    Controller = "Common";
                    ActionName = "ChangePassword";

                    HttpContext.Session.SetString("Email", objDatawithSP.PANNumber);

                    if (IsRemember == "1")
                    {
                        SetCookie(AdminID.ToString(), AdminName, "MasterAdmin");
                        Response.Cookies.Append("PANNumber", PANNumber, option);
                    }
                    return(RedirectToAction(ActionName, Controller, new { RoleName = Role }));
                }
            }
        }
        public IActionResult ValidateSuperAdminLogOn(string EmailID, string Password, string IsRemember)
        {
            //EmailID = "*****@*****.**";

            if (!ReCaptchaPassed(
                    Request.Form["g-recaptcha-response"], // that's how you get it from the Request object
                    _configuration.GetSection("GoogleReCaptcha:SecretKey").Value
                    ))
            {
                TempData["InvalidCredential"] = "Captcha verification failed.";
                return(RedirectToAction("SuperAdminLogin", "Account"));
            }

            string ActionName     = this.ControllerContext.RouteData.Values["action"].ToString();
            string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            Int32? UserLoginID    = HttpContext.Session.GetInt32("UserID");
            string ErrorMessage   = string.Empty;

            try
            {
                Password = SecurityHelperService.Encrypt(Password);
                FinocartMaster objDatawithSP = _SuperAdminRepository.ValidateLogin(EmailID, Password);
                HttpContext.Session.SetString("Role", "SuperAdmin");
                CookieOptions option = new CookieOptions();
                option.Expires = DateTime.Now.AddDays(2);
                Response.Cookies.Append("RoleAccess", "SuperAdmin", option);

                if (objDatawithSP == null)
                {
                    TempData["InvalidCredential"] = "Enter valid credential";
                    return(RedirectToAction("SuperAdminLogin", "Account"));
                }
                else
                {
                    var UserID   = objDatawithSP.ID;
                    var UserName = objDatawithSP.Name;
                    HttpContext.Session.SetInt32("UserID", UserID);
                    HttpContext.Session.SetString("LoginName", UserName);
                    HttpContext.Session.SetString("JWToken", GenerateJWTToken(UserName));
                    if (IsRemember == "1")
                    {
                        SetCookie(UserID.ToString(), UserName, "SuperAdmin");
                        Response.Cookies.Append("EmailID", EmailID, option);
                    }

                    var Res = _CommonRepository.AuditTrailLog("Login", "Super Admin Login", UserID, 0);

                    if (objDatawithSP.IsTemporaryPassword == false)
                    {
                        TempData["Role"] = "SuperAdmin";

                        return(RedirectToAction("SuperAdminDashBoard", "AnchorCompany"));
                    }
                    else
                    {
                        var data = Encoding.UTF8.GetBytes("SuperAdmin");
                        var Role = Convert.ToBase64String(data);
                        HttpContext.Session.SetString("Email", objDatawithSP.EmailId);
                        return(RedirectToAction("ChangePassword", "Common", new { RoleName = Role }));
                    }
                }
            }
            catch (Exception ex)
            {
                var st        = new StackTrace(ex, true);
                var frame     = st.GetFrame(0);
                int ErrorLine = frame.GetFileLineNumber();
                var Result    = _CommonRepository.LogManagement(ControllerName, ActionName, ex.Message, ErrorLine, UserLoginID);
                return(RedirectToAction("ErrorPage", "Common"));
            }
        }
        public IActionResult ValidateUserLogOn(string Email, string Password, string IsRemember)
        {
            if (!ReCaptchaPassed(
                    Request.Form["g-recaptcha-response"], // that's how you get it from the Request object
                    _configuration.GetSection("GoogleReCaptcha:SecretKey").Value
                    ))
            {
                TempData["InvalidCredential"] = "Captcha verification failed.";
                return(RedirectToAction("UserLogin", "Account"));
            }

            string ControllerActionName = this.ControllerContext.RouteData.Values["action"].ToString();
            string ControllerName       = this.ControllerContext.RouteData.Values["controller"].ToString();
            Int32? LoginUserID          = HttpContext.Session.GetInt32("UserID");

            string ErrorMessage = string.Empty;

            try
            {
                string pw = SecurityHelperService.Decrypt("8qLsuVEBHnIzavnjCKcC5g==");
                Password = SecurityHelperService.Encrypt(Password);
                UserLoginModel userModel  = _venderRepository.validateUser(Email, Password);
                string         Controller = "";
                string         ActionName = "";
                HttpContext.Session.SetString("Role", "InternalUser");
                if (userModel == null)
                {
                    string strLockRes = _adminRepository.LockedUser(Email);
                    TempData["InvalidCredential"] = strLockRes;
                    //TempData["InvalidCredential"] = "Enter valid credential";
                    return(RedirectToAction("UserLogin", "Account"));
                }
                else
                {
                    var UserID      = Convert.ToInt32(userModel.UserID);
                    var UserName    = userModel.Name;
                    var CompanyId   = userModel.CompanyID;
                    var RoleAccess  = userModel.RoleAccess;
                    var Companyname = userModel.Companyname;

                    Response.Cookies.Delete("RoleAccess");

                    CookieOptions option = new CookieOptions();
                    option.Expires = DateTime.Now.AddDays(2);
                    Response.Cookies.Append("RoleAccess", RoleAccess, option);

                    HttpContext.Session.SetInt32("UserID", UserID);
                    HttpContext.Session.SetString("LoginName", UserName);
                    HttpContext.Session.SetInt32("CompanyID", CompanyId);
                    HttpContext.Session.SetString("RoleAccess", RoleAccess);
                    HttpContext.Session.SetString("Companyname", Companyname);
                    HttpContext.Session.SetString("JWToken", GenerateJWTToken(UserName));

                    if (IsRemember == "1")
                    {
                        SetCookie(UserID.ToString(), UserName, "InternalUser");
                        Response.Cookies.Append("Email", Email, option);
                    }
                    var Res = _CommonRepository.AuditTrailLog("LoginPage", "LoginPage", UserID, 0);
                    if (userModel.IsTemporaryPassword == false)
                    {
                        if (RoleAccess == "Vendor Company")
                        {
                            Controller = "Vendor";
                            ActionName = "VendorDashboardMain";
                        }
                        if (RoleAccess == "Anchor Company")
                        {
                            var    lstchecklimit  = _companyRepository.CheckSetLimit(CompanyId);
                            string PercentageRate = Convert.ToString(lstchecklimit.ElementAt(0).PercentageRate);
                            string PaymentDays    = Convert.ToString(lstchecklimit.ElementAt(0).PaymentDays);
                            //if (PercentageRate != "" && PaymentDays != "")
                            //{
                            Controller = "AnchorCompany";
                            ActionName = "AnchorDashboard";
                            //}
                            //else
                            //{
                            //    //Controller = "AnchorCompany";
                            //    //ActionName = "AnchorDashboard";
                            //    Controller = "AnchorCompany";
                            //    ActionName = "SetLimit";

                            //}
                        }

                        if (RoleAccess == "Both")
                        {
                            Controller = "AnchorCompany";
                            ActionName = "AnchorDashboard";
                        }
                        if (RoleAccess == "Bank")
                        {
                            Controller = "BankCompany";
                            ActionName = "BankDashboard";
                        }
                        return(RedirectToAction(ActionName, Controller));
                    }
                    else
                    {
                        var data = Encoding.UTF8.GetBytes("InternalUser");
                        var Role = Convert.ToBase64String(data);
                        HttpContext.Session.SetString("Email", userModel.Email);
                        Controller = "Common";
                        ActionName = "ChangePassword";
                        SetCookie(UserID.ToString(), UserName, Role);
                        return(RedirectToAction(ActionName, Controller, new { RoleName = Role }));
                    }
                }
            }
            catch (Exception ex)
            {
                var st        = new StackTrace(ex, true);
                var frame     = st.GetFrame(0);
                int ErrorLine = frame.GetFileLineNumber();
                var Result    = _CommonRepository.LogManagement(ControllerName, ControllerActionName, ex.Message, ErrorLine, LoginUserID);
                return(RedirectToAction("ErrorPage", "Common"));
            }
        }
Example #10
0
        public ActionResult AddUser(UserModel objUserPage)
        {
            string ActionName     = this.ControllerContext.RouteData.Values["action"].ToString();
            string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            Int32? UserID         = HttpContext.Session.GetInt32("UserID");
            string ErrorMessage   = string.Empty;

            try
            {
                string randomPassword = _CommonRepository.GeneratePassword();
                if (objUserPage.UserID == 0)
                {
                    objUserPage.Password = SecurityHelperService.Encrypt(randomPassword);
                }
                Int32? UserId       = HttpContext.Session.GetInt32("UserID");
                Int32? AccessViewId = objUserPage.AccessViewID;
                string CompanyName  = HttpContext.Session.GetString("Companyname");

                objUserPage.CreatedBy = UserId;
                objUserPage.UpdatedBy = UserId;

                var Result = _Userepository.InsertUpdateUserRecord(objUserPage);

                if (objUserPage.UserID == 0)
                {
                    if (Result > 0)
                    {
                        //string Template = string.Empty;
                        IEnumerable <GetUserMailTemplate> lstAwaitedInvVendorsView = _lookUpRepository.getUserMailTemplate(AccessViewId);
                        string path = lstAwaitedInvVendorsView.ElementAt(0).Template;
                        string EMAIL_TOKEN_PAYMENT_LINK = "##$$PAYMENT_LINK$$##";
                        string paymentLink = "http://dotnet.brainvire.com/Finocart/Account/UserLogin";///change url

                        string emailToAddress = objUserPage.Email;
                        string subject        = "User registration";
                        string body           = path;
                        body = body.Replace("@@Panno@@", objUserPage.Email);
                        body = body.Replace("@@UserName@@", objUserPage.Name);
                        body = body.Replace("@@CompanyName@@", CompanyName);
                        body = body.Replace("@@ProjectName@@", "Finocart");
                        body = body.Replace(EMAIL_TOKEN_PAYMENT_LINK, paymentLink);
                        body = body.Replace("@@Password@@", randomPassword);
                        IEnumerable <LookupDetails> lookupDetails = _lookUpRepository.getLookupDetailByKey("SMTPInfo");
                        _CommonRepository.SendEmail(lookupDetails, emailToAddress, subject, body, true);

                        User objDatawithSP = _CommonRepository.CheckUserByEmail(objUserPage.Email, false);
                        if (objDatawithSP != null)
                        {
                            string DescriptionMessage = "Congratulations your registered on the Finocart Portal. Now you can access the portal and create your users ";

                            var Result1 = _Userepository.AddUserNotificationMessage(objDatawithSP.UserID, DescriptionMessage, null, UserId);
                        }
                    }
                    TempData["AddResult"] = Result;
                }
                else
                {
                    TempData["UpdateResult"] = Result;
                }
            }
            catch (Exception ex)
            {
                var st        = new StackTrace(ex, true);
                var frame     = st.GetFrame(0);
                int ErrorLine = frame.GetFileLineNumber();
                var Result    = _CommonRepository.LogManagement(ControllerName, ActionName, ex.Message, ErrorLine, UserID);
                return(RedirectToAction("ErrorPage", "Common"));

                TempData["FailureMessage"] = "We are sorry, something went wrong. Please try again later";
            }

            return(RedirectToAction("UserList", "User"));
        }
        public IActionResult updateNewPassword(ChangePasswordModel changePassword)
        {
            string ActionName       = this.ControllerContext.RouteData.Values["action"].ToString();
            string ControllerName   = this.ControllerContext.RouteData.Values["controller"].ToString();
            Int32? UserID           = HttpContext.Session.GetInt32("UserID");
            string ErrorMessage     = string.Empty;
            var    lstEmailIDofBank = _companyRepository.GetAnchorEmail(Convert.ToString(changePassword.UserId));

            changePassword.Email = lstEmailIDofBank.ElementAt(0).Contact_email;
            try
            {
                var Result  = "";
                var Actions = "";
                changePassword.NewPassword = SecurityHelperService.Encrypt(changePassword.NewPassword);
                changePassword.OldPassword = SecurityHelperService.Encrypt(changePassword.OldPassword);
                var data = Encoding.UTF8.GetBytes(changePassword.Role);
                var Role = Convert.ToBase64String(data);
                if (HttpContext.Session.GetInt32("UserID") != null)
                {
                    if (changePassword.Role == "InternalUser")
                    {
                        Actions = "UserLogin";
                        User objDatawithSP = _empRepository.CheckUser(changePassword.Email, changePassword.OldPassword);
                        if (objDatawithSP != null)
                        {
                            Result = objDatawithSP.Password;
                        }
                    }
                    if (changePassword.Role == "MasterAdmin")
                    {
                        Actions = "AdminLogin";
                        Company objDatawithSP = _empRepository.CheckAdmin(changePassword.Email, changePassword.OldPassword);
                        if (objDatawithSP != null)
                        {
                            Result = objDatawithSP.Password;
                        }
                    }
                    if (changePassword.Role == "SuperAdmin")
                    {
                        Actions = "SuperAdminLogin";
                        FinocartMaster objDatawithSP = _empRepository.CheckSuperAdmin(changePassword.Email, changePassword.OldPassword);
                        if (objDatawithSP != null)
                        {
                            Result = objDatawithSP.Password;
                        }
                    }

                    if (Result != "")
                    {
                        var Data = _empRepository.UpdateNewPassword(changePassword);
                    }

                    else
                    {
                        TempData["WrongPassword"] = "******";
                        return(RedirectToAction("ChangePassword", "Common", new { RoleName = Role }));
                    }
                    if (Result != "")
                    {
                        string emailToAddress = lstEmailIDofBank.ElementAt(0).Contact_email;
                        string AnchorName     = lstEmailIDofBank.ElementAt(0).Contact_Name;
                        string BankName       = HttpContext.Session.GetString("LoginName");
                        string Template       = string.Empty;
                        int    Id             = 1;
                        IEnumerable <GetChangePasswordMailTemplate> lstAwaitedInvVendorsView = _companyRepository.GetChangePasswordMailTemplate(Template);
                        string path = lstAwaitedInvVendorsView.ElementAt(0).Template;
                        //string path = "";
                        string subject = "Change Password";
                        string body    = path;
                        body = body.Replace("@@User@@", AnchorName);
                        body = body.Replace("@@BankName@@", BankName);
                        body = body.Replace("@@mentiondateandtime", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"));
                        IEnumerable <LookupDetails> lookupDetails = _lookUpRepository.getLookupDetailByKey("SMTPInfo");
                        _CommonRepository.SendEmail(lookupDetails, emailToAddress, subject, body, true);
                    }
                    return(RedirectToAction(Actions, "Account"));
                }
                else
                {
                    return(RedirectToAction("ChangePassword", "Common", new { RoleName = Role }));
                }
            }
            catch (Exception ex)
            {
                var st        = new StackTrace(ex, true);
                var frame     = st.GetFrame(0);
                int ErrorLine = frame.GetFileLineNumber();
                var Result    = _CommonRepository.LogManagement(ControllerName, ActionName, ex.Message, ErrorLine, UserID);
                return(RedirectToAction("ErrorPage", "Common"));
            }
        }
        public IActionResult setChangePassword(ChangePasswordModel objChangePassword)

        {
            string ActionName     = this.ControllerContext.RouteData.Values["action"].ToString();
            string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            Int32? UserID         = HttpContext.Session.GetInt32("UserID");
            string ErrorMessage   = string.Empty;

            try
            {
                //string pw = SecurityHelperService.Decrypt("ueNl4Gl98pKy3m0G6CaqBsi6jSC58DX8");
                var Result  = "";
                var Actions = "";
                objChangePassword.NewPassword = SecurityHelperService.Encrypt(objChangePassword.NewPassword);
                objChangePassword.OldPassword = SecurityHelperService.Encrypt(objChangePassword.OldPassword);
                var data = Encoding.UTF8.GetBytes(objChangePassword.Role);
                var Role = Convert.ToBase64String(data);
                if (HttpContext.Session.GetInt32("UserID") != null)
                {
                    if (objChangePassword.Role == "InternalUser")
                    {
                        Actions = "UserLogin";
                        //IEnumerable<User> objDatawithSP = _empRepository.CheckUserPassword();
                        //objDatawithSP = objDatawithSP.Where(x => x.Password == objChangePassword.OldPassword && x.Email == objChangePassword.Email);
                        User objDatawithSP = _empRepository.CheckUser(objChangePassword.Email, objChangePassword.OldPassword);
                        if (objDatawithSP != null)
                        {
                            Result = objDatawithSP.Password;
                        }
                    }
                    if (objChangePassword.Role == "MasterAdmin")
                    {
                        Actions = "AdminLogin";
                        //IEnumerable<Company> objDatawithSP = _empRepository.CheckAdminPassword();
                        ////objDatawithSP = objDatawithSP.Where(x => x.Password == objChangePassword.OldPassword && (x.Email == objChangePassword.Email || x.PANNumber == objChangePassword.Email));
                        //objDatawithSP = objDatawithSP.Where(x => x.Password == objChangePassword.OldPassword && x.Pan_number == objChangePassword.Email);
                        Company objDatawithSP = _empRepository.CheckAdmin(objChangePassword.Email, objChangePassword.OldPassword);
                        if (objDatawithSP != null)
                        {
                            Result = objDatawithSP.Password;
                        }
                    }
                    if (objChangePassword.Role == "SuperAdmin")
                    {
                        Actions = "SuperAdminLogin";
                        //IEnumerable<FinocartMaster> objDatawithSP = _empRepository.CheckSuperAdminPassword();
                        //objDatawithSP = objDatawithSP.Where(x => x.Password == objChangePassword.OldPassword && x.EmailId == objChangePassword.Email);
                        FinocartMaster objDatawithSP = _empRepository.CheckSuperAdmin(objChangePassword.Email, objChangePassword.OldPassword);
                        if (objDatawithSP != null)
                        {
                            Result = objDatawithSP.Password;
                        }
                    }

                    if (Result != "")
                    {
                        var Data = _empRepository.UpdateNewPassword(objChangePassword);
                        return(RedirectToAction(Actions, "Account"));
                    }
                    else
                    {
                        TempData["WrongPassword"] = "******";
                        return(RedirectToAction("ChangePassword", "Common", new { RoleName = Role }));
                    }
                }
                else
                {
                    return(RedirectToAction("ChangePassword", "Common", new { RoleName = Role }));
                }
            }
            catch (Exception ex)
            {
                var st        = new StackTrace(ex, true);
                var frame     = st.GetFrame(0);
                int ErrorLine = frame.GetFileLineNumber();
                var Result    = _CommonRepository.LogManagement(ControllerName, ActionName, ex.Message, ErrorLine, UserID);
                return(RedirectToAction("ErrorPage", "Common"));
            }
        }