Пример #1
0
        public ActionResult SignUp(User user)
        {
            if (this.Session["CaptchaImageText"].ToString() == user.SecurityCode)
            {
                string newSalt = PasswordEncryption.RandomString();
                user.Password    = PasswordEncryption.encryptPassword(user.Password, newSalt);
                user.Email       = user.NewEmail;
                user.RoleId      = 1;
                user.Status      = true;
                user.step_status = 0;

                UserAccess ua = new UserAccess();
                if (ua.InsertUser(user) >= 1)
                {
                    //ViewBag.SuccessMsg = "Your profile Successfully created.";
                    TempData["status"] = "success";
                    //If succeed update step table to step2
                    StepAccess sa = new StepAccess();
                    //if (sa.updateStepNumberByUserId(ua.getUserId(user.Email), 1))
                    return(RedirectToAction("UserLogin", "Login"));
                }
                TempData["status"] = "fail";
                //ViewBag.ErrorMsg = "Failed to Sign up try again!";
            }
            else
            {
                TempData["status"] = "captchaFail";
                //ViewBag.ErrorMsg = "Entered Security Code is Not Correct!";
                TempData["ErrorModel"] = user;
            }


            //return View();
            return(RedirectToAction("SignUp"));
        }
        public ActionResult CreateFirstSuperUser(User user)
        {
            //user.Password = PasswordEncryption.encryptPassword(user.Password);

            string newSalt = PasswordEncryption.RandomString();

            user.Password    = PasswordEncryption.encryptPassword(user.Password, newSalt);
            user.Email       = user.NewEmail;
            TempData["User"] = user;
            return(RedirectToAction("Setup", "SetupCompany", new { id = 0, type = "CompanyEmployee" }));
        }
Пример #3
0
        /*
         *
         * Frontend page: Reset Password page
         * Title:  Update Password
         * Designed: Irfan Mam
         * User story:
         * Developed: Irfan MAM
         * Date created: 1/17/2016
         *
         */
        public bool resetPassword(int userId, ResetPassword resetPasswordModel)
        {
            DataHandler dataHandler = new DataHandler();
            string      newSalt     = PasswordEncryption.RandomString();

            resetPasswordModel.Password = PasswordEncryption.encryptPassword(resetPasswordModel.Password, newSalt);

            List <object[]> paramertList = new List <object[]>();

            paramertList.Add(new object[] { "@user_id", userId });
            paramertList.Add(new object[] { "@password", resetPasswordModel.Password });


            try
            {
                return(dataHandler.ExecuteSQLWithReturnVal("spUpdatePassword", paramertList) > 0 ? true : false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult LinkDealer(DealerUserModel user)
        {
            //initialize properties of user object
            user.PhoneNumber = user.PhoneNumber2;
            user.CreatedBy   = userData.UserId;
            user.IsDelete    = false;
            user.Status      = true;
            user.Company_Id  = userData.Company_Id;
            user.BranchId    = userData.BranchId;
            user.RoleId      = 4;
            user.Email       = user.NewEmail;

            BranchAccess ba   = new BranchAccess();
            Loan         loan = new Loan();

            //Check Session["oneLoanDashboard"] is not null
            if (Session["oneLoanDashboard"] != null)
            {
                //convert session object to loan object
                loan = (Loan)Session["oneLoanDashboard"];
            }
            //Check Session["loanDashboardJoinDealer"] is not null
            if (Session["loanDashboardJoinDealer"] != null)
            {
                //convert session object to loan object
                loan = (Loan)Session["loanDashboardJoinDealer"];
            }
            //initialize non registered branch id
            user.NonRegBranchId = loan.NonRegBranchId;
            //initialize loan id
            user.LoanId = loan.LoanId;
            //encrypt given password
            string passwordTemp = user.Password;

            UserAccess ua = new UserAccess();

            string newSalt = PasswordEncryption.RandomString();

            user.Password       = PasswordEncryption.encryptPassword(user.Password, newSalt);
            user.ActivationCode = Guid.NewGuid().ToString();
            //report rights
            string[] arrList = new string[user.ReportRightsList.Count];
            int      k       = 0;

            foreach (var y in user.ReportRightsList)
            {
                //Check whether a particular report right is given to user
                if (y.active)
                {
                    arrList[k] = y.rightId;
                    k++;
                }
            }
            arrList           = arrList.Where(x => !string.IsNullOrEmpty(x)).ToArray();
            user.ReportRights = string.Join(",", arrList);
            //Insert dealer user details and retrieve user id of inserted user
            int newUserId = ua.InsertDealerUser(user);

            //Check user id is not 0
            if (newUserId != 0)
            {
                //Generate email to send username and password to created dealer user
                string body = "Hi " + user.FirstName + "! <br /><br /> Your account has been successfully created. Below in your account detail." +
                              "<br /><br /> User name: " + user.UserName +
                              "<br /> Password : <b>" + passwordTemp +
                              "<br />Click <a href='www.dfpso.com'>here</a> to activate your account." +
                              "<br /><br/> Thanks,<br /> Admin.";

                Email email = new Email(user.Email);

                Session["abcRol"]  = user.RoleId;
                Session["abcBrnc"] = user.BranchId;
                email.SendMail(body, "Account details");
                //insert log record after user is created
                Log log = new Log(userData.UserId, userData.Company_Id, user.BranchId, user.LoanId, "Create Dealer Account", "Inserted Dealer : " + user.UserName, DateTime.Now);

                int islog = (new LogAccess()).InsertLog(log);

                TempData["msg"] = 1;
                return(RedirectToAction("LinkDealer"));
            }
            else
            {
                TempData["msg"] = 2;
                return(RedirectToAction("LinkDealer"));
            }
        }
        public ActionResult Create(User user)
        {
            int currentUser = 0;

            try
            {
                currentUser = int.Parse(Session["userId"].ToString());
            }
            catch (Exception) {
                return(RedirectToAction("UserLogin", "Login"));
            }

            user.CreatedBy = _createById;
            user.IsDelete  = false;
            user.Status    = false;

            //Set admin branch to new user
            if (_curUserRoleId == 2)
            {
                user.BranchId = _curBranchId;
            }

            //Check role is selected
            if (user.RoleId == 0)
            {
                user.RoleId = 2;
            }

            //Check branch is selected
            if (_curUserRoleId == 1 && user.BranchId == 0)
            {
                user.BranchId = _curBranchId;
            }
            string passwordTemp = user.Password;

            UserAccess ua = new UserAccess();

            string newSalt = PasswordEncryption.RandomString();

            user.Password = PasswordEncryption.encryptPassword(user.Password, newSalt);
            user.Email    = user.NewEmail;

            //Check this
            CompanyAccess ca      = new CompanyAccess();
            Company       company = new Company();//ca.GetCompanyDetailsByFirstSpUserId(currentUser);

            //Insert user
            user.Company_Id = company.CompanyId;
            int res = ua.InsertUser(user);

            //Insert new user to user activation table
            string activationCode = Guid.NewGuid().ToString();
            int    userId         = (new UserAccess()).getUserId(user.Email);

            res = ua.InsertUserActivation(userId, activationCode);
            if (res == 1)
            {
                ViewBag.SuccessMsg = "Data Successfully inserted!";

                string body = "Hi " + user.FirstName + "! <br /><br /> Your account has been successfully created. Below in your account detail." +
                              "<br /><br /> User name: " + user.UserName +
                              "<br /> Password : <b>" + passwordTemp +
                              "<br />Click <a href='http://localhost:57318/CreateUser/ConfirmAccount?userId=" + userId + "&activationCode=" + activationCode + "'>here</a> to activate your account." +
                              "<br /><br/> Thanks,<br /> Admin.";

                Email email = new Email(user.Email);
                email.SendMail(body, "Account details");


                // check the user as superadmin or admin..
                if (user.RoleId == 1 || user.RoleId == 2)
                {
                    ViewBag.SuccessMsg = "User Successfully Created";



                    return(RedirectToAction("create", new { lbls = ViewBag.SuccessMsg }));
                }

                Session["editUserIds"] = userId;


                return(RedirectToAction("SetRights", "EditRights", new { @lbl1 = ViewBag.SuccessMsg }));
            }
            else
            {
                ViewBag.ErrorMsg = "Failed to create user!";

                //Restrict to create above user role
                RoleAccess      ra           = new RoleAccess();
                List <UserRole> roleList     = ra.GetAllUserRoles();
                List <UserRole> tempRoleList = new List <UserRole>();

                for (int i = roleList[_curUserRoleId - 1].RoleId; i <= roleList.Count && _curUserRoleId != 3; i++)
                {
                    UserRole tempRole = new UserRole()
                    {
                        RoleId   = roleList[i - 1].RoleId,
                        RoleName = roleList[i - 1].RoleName
                    };
                    tempRoleList.Add(tempRole);
                }

                ViewBag.RoleId = new SelectList(tempRoleList, "RoleId", "RoleName");

                // get all branches
                List <Branch> branchesLists = (new BranchAccess()).getBranches(_companyId);
                ViewBag.BranchId = new SelectList(branchesLists, "BranchId", "BranchName");


                return(PartialView("Create"));
            }
        }