コード例 #1
0
        public ActionResult UserNav(Guid userId)
        {
            var user = new SMR.KM.Business.Models.User();

            user = _userServices.GetUser(userId, CurrentUser);
            return(PartialView("UserNav", user));
        }
コード例 #2
0
        //
        // GET: /User/Create

        public ActionResult Create()
        {
            try
            {
                if (_log.IsInfoEnabled)
                {
                    _log.Info("Calling GetPlant method of UserService.");
                }
                if (Request.IsAuthenticated)
                {
                    var user = new SMR.KM.Business.Models.User()
                    {
                        Plants     = _userServices.GetPlant(),
                        UserGroups = _userServices.GetUserGroups()
                    };
                    return(View(user));
                }
                else
                {
                    return(RedirectToAction("Logon", "Account"));
                }
            }
            catch (Exception ex)
            {
                if (_log.IsErrorEnabled)
                {
                    _log.Error(ex.Message, ex);
                }
                throw ex;
            }
        }
コード例 #3
0
        public ActionResult Create(SMR.KM.Business.Models.User user)
        {
            try
            {
                if (_log.IsInfoEnabled)
                {
                    _log.Info("Calling AddUser method of UserService.");
                }
                if (string.IsNullOrEmpty(user.UserAvatar))
                {
                    ModelState.Remove("UserAvatar");
                    user.UserAvatar = Url.Content("~/Content/Images/Anonymsuser.jpg");
                }
                // bool canCreateProfile = _permissionServices.CanCreateProfile(CurrentUser, "Create", "User");
                //if (!canCreateProfile)
                //{
                //    throw new Exception("You are not authorized to create user.");
                //}
                if (ModelState.IsValid)
                {
                    MembershipCreateStatus createStatus = MembershipService.CreateUser(user.UserName, user.Password, user.Email, user.PlantId);
                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        var item = _userServices.UserIdByUserName(user.UserName);
                        _userServices.AddUser(user, CurrentUser);

                        string message = item.IsAnonymous ? "use the password you registered with" : "use your windows logon password";
                        _emailServices.RegisteredUserEmail(user.Email, string.IsNullOrEmpty(user.FirstName) && string.IsNullOrEmpty(user.LastName) ? user.UserName : string.IsNullOrEmpty(user.FirstName) ? user.LastName : string.IsNullOrEmpty(user.LastName) ? user.FirstName : user.FirstName.ToUpper() == user.LastName.ToUpper() ? user.FirstName.ToUpper() :user.LastName.ToUpper() + " " + user.FirstName.ToUpper(), user.UserId, message);
                        return(RedirectToAction("Index", "User"));
                    }
                    else
                    {
                        ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                    }
                }
            }
            catch (DataException ex)
            {
                if (_log.IsErrorEnabled)
                {
                    _log.Error(ex.Message, ex);
                }
                throw ex;
            }
            user.Plants     = _userServices.GetPlant();
            user.UserGroups = _userServices.GetUserGroups();
            return(View(user));
        }
コード例 #4
0
 public ActionResult ForgotPassword(SMR.KM.Business.Models.User userForgot)
 {
     try
     {
         _log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
         if (!string.IsNullOrEmpty(userForgot.UserName))
         {
             var user = _userServices.GetUser(userForgot.UserName);
             if (user != null)
             {
                 if (user.IsAnonymous == false)
                 {
                     throw new Exception("You are registered as an active directory user. Please use your window credentials to logon.");
                 }
                 else
                 {
                     string        decryptedPwd   = KMEncryptDecrypt.Decrypt(user.Password, SiteConfig.KMEncryptDecryptKey);
                     EmailServices oEmailServices = new EmailServices();
                     bool          isSucess       = oEmailServices.ForgotPasswordEmail(user, decryptedPwd);
                     if (isSucess)
                     {
                         throw new Exception("Please check your mailbox for password.");
                     }
                 }
             }
             else
             {
                 throw new Exception("Specified user does not exist.");
             }
         }
         else
         {
             throw new Exception("Username is required.");
         }
         return(View());
     }
     catch (Exception ex)
     {
         if (_log.IsErrorEnabled)
         {
             _log.Error(ex.Message, ex);
         }
         throw ex;
     }
 }
コード例 #5
0
 public ActionResult Edit(SMR.KM.Business.Models.User user, string initialChar)
 {
     try
     {
         if (_log.IsInfoEnabled)
         {
             _log.Info("Calling EditUser method of UserService.");
         }
         if (ModelState.IsValid)
         {
             string hashedPassword = user.PasswordCheck == user.Password ? user.Password : KMEncryptDecrypt.Encrypt(user.Password, SiteConfig.KMEncryptDecryptKey);
             if (user.IsAnonymous == false)
             {
                 user.IsAnonymous = true;
             }
             else
             {
                 user.IsAnonymous = false;
             }
             user.Password = hashedPassword;
             _userServices.EditUser(user, CurrentUser);
             user.Plants         = _userServices.GetPlant();
             user.UserGroups     = _userServices.GetUserGroups();
             ViewBag.InitialChar = initialChar;
             return(RedirectToAction("Details", "User", new { id = user.UserId, userName = initialChar }));
         }
     }
     catch (Exception ex)
     {
         if (_log.IsErrorEnabled)
         {
             _log.Error(ex.Message, ex);
         }
         throw ex;
     }
     user.Plants     = _userServices.GetPlant();
     user.UserGroups = _userServices.GetUserGroups();
     return(View(user));
 }
コード例 #6
0
 public void UploadImage(SMR.KM.Business.Models.User user)
 {
 }