コード例 #1
0
        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 }));
        }
コード例 #2
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"));
        }