Example #1
0
        private static bool CanEditStateUser(UserViewData StateUserData, UserViewData EditorData)
        {
            if (EditorData.IsCMSLevel)
            {
                return(EditorData.IsCMSAdmin);   //Will approve all State Level users
            }
            else if (EditorData.IsUserStateScope && (EditorData.StateFIPS == StateUserData.StateFIPS))
            {
                //Ship directors are only edited by CMS Admins
                if (StateUserData.IsShipDirector)
                {
                    return(false);
                }
                else if (StateUserData.IsStateAdmin)
                {
                    if (StateUserData.IsStateApproverDesignate)
                    {
                        return(EditorData.IsShipDirector);
                    }
                    else
                    {
                        return(EditorData.IsShipDirector || EditorData.IsStateApproverDesignate);
                    }
                }
                else
                {
                    return(EditorData.IsStateAdmin);
                }
            }

            return(false);
        }
Example #2
0
    public IActionResult /*UserViewData*/ GetUser_RatingById(int Rating_id, int User_id)
    {
        var session           = HttpContext.Get <LoggableEntities>(_context);
        var current_User      = session == null ? null : session.User;
        var current_Admin     = session == null ? null : session.Admin;
        var allowed_sources   = ApiTokenValid ? _context.Rating : _context.Rating;
        var source            = allowed_sources.FirstOrDefault(s => s.Id == Rating_id);
        var can_view_by_token = ApiTokenValid || true;

        if (source == null || !can_view_by_token)
        {
            return(NotFound());
        }
        var allowed_targets = ApiTokenValid ? _context.User : _context.User;
        var item            = (from link in _context.User_Rating
                               where link.RatingId == source.Id
                               from target in allowed_targets
                               where link.UserId == target.Id
                               select target).OrderBy(i => i.CreatedDate)
                              .Select(PortableRecipes.Models.User.FilterViewableAttributes(current_User, current_Admin))
                              .FirstOrDefault(t => t.Id == User_id);

        if (item == null)
        {
            return(NotFound());
        }
        item = PortableRecipes.Models.User.WithoutImages(item);
        return(Ok(UserViewData.FromUser(item)));
    }
Example #3
0
        private static bool CanAddUserToSubStateScope(UserViewData AdminData, string StateFIPS)
        {
            //CMS Admins can create users of all state roles
            if (AdminData.IsCMSAdmin)
            {
                return(true);
            }
            else if (AdminData.StateFIPS == StateFIPS)
            {
                if (AdminData.IsStateAdmin)
                {
                    return(true);
                }
                else if (AdminData.IsUserSubStateRegionalScope)
                {
                    //The only possibility from now on, is Editor is a Sub State User.
                    foreach (UserRegionalAccessProfile subStateUserProfile in AdminData.RegionalProfiles)
                    {
                        if (subStateUserProfile.IsAdmin)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Example #4
0
 public static bool IsAdmin(UserViewData AdminViewData, State UserState)
 {
     if (AdminViewData.IsCMSLevel)
     {
         return(AdminViewData.IsCMSAdmin);
     }
     else
     {
         if (AdminViewData.StateFIPS != UserState.Code)
         {
             return(false);
         }
         else
         {
             if (AdminViewData.IsUserStateScope)
             {
                 return(AdminViewData.IsAdmin);
             }
             else
             {
                 foreach (UserRegionalAccessProfile profile in AdminViewData.RegionalProfiles)
                 {
                     if (profile.IsAdmin && profile.IsActive)
                     {
                         return(true);
                     }
                 }
                 return(false);
             }
         }
     }
 }
Example #5
0
        protected void dataSourceUserView_Updated(object sender, ObjectContainerDataSourceStatusEventArgs e)
        {
            if (!IsValid())
            {
                return;
            }

            UserViewData ChangedUserData = (UserViewData)e.Instance;

            //Update IsActive of UserData with what we got from Updating method.
            //ChangedUserData.IsActive = IsActiveUser;

            if (UserBLL.UpdateUserProfile(GetChangedUserProfile(ChangedUserData), this.AccountInfo.UserId))
            {
                if (UserBLL.UpdateUserAccount(this.AccountInfo, this.AccountInfo.UserId))
                {
                    DisplayMessage("The submitted information has been saved successfully.", false);
                }
                else
                {
                    DisplayMessage("Unable to save Zip and County of Counseling location. However, the rest of the profile information has been saved successfully.", true);
                }
            }
            else
            {
                DisplayMessage("Sorry. Unable to save the information. Please contact support for assistance.", true);
            }

            FetchUserData();
        }
Example #6
0
    public IActionResult Update([FromBody] UserViewData item)
    {
        var session       = HttpContext.Get <LoggableEntities>(_context);
        var current_User  = session == null ? null : session.User;
        var current_Admin = session == null ? null : session.Admin;
        var allowed_items = ApiTokenValid ? _context.User : (current_User != null ? (from _User in _context.User where _User.Id == current_User.Id
                                                                                     select _User) : _context.User);

        if (!allowed_items.Any(i => i.Id == item.Id))
        {
            return(Unauthorized());
        }
        var new_item = UserViewData.FromUserViewData(item, _context);

        if (current_User != null && new_item.Id == current_User.Id)
        {
            HttpContext.Set <LoggableEntities>(_context, new LoggableEntities()
            {
                User = new_item
            });
        }
        var can_edit_by_token = ApiTokenValid || true;

        if (item == null || !can_edit_by_token)
        {
            return(Unauthorized());
        }
        // throw new Exception("Unauthorized edit attempt");
        _context.Update(new_item);
        _context.Entry(new_item).Property(x => x.Username).IsModified    = false;
        _context.Entry(new_item).Property(x => x.Email).IsModified       = false;
        _context.Entry(new_item).Property(x => x.CreatedDate).IsModified = false;
        _context.SaveChanges();
        return(Ok());
    }
Example #7
0
    public IActionResult /*UserViewData*/ Create()
    {
        var session       = HttpContext.Get <LoggableEntities>(_context);
        var current_User  = session == null ? null : session.User;
        var current_Admin = session == null ? null : session.Admin;

        if (_context.User.Any(u => u.Username == null || u.Email == null || u.Username == "" || u.Email == ""))
        {
            return(Unauthorized());
        }
        // throw new Exception("Unauthorized create attempt");
        var can_create_by_token = ApiTokenValid || true;

        if (!can_create_by_token)
        {
            return(Unauthorized());
        }
        // throw new Exception("Unauthorized create attempt");
        var item = new User()
        {
            CreatedDate = DateTime.Now, Id = _context.User.Max(i => i.Id) + 1
        };

        _context.User.Add(PortableRecipes.Models.User.FilterViewableAttributesLocal(current_User, current_Admin)(item));
        _context.SaveChanges();
        item = PortableRecipes.Models.User.WithoutImages(item);
        return(Ok(UserViewData.FromUser(item)));
    }
Example #8
0
    public IActionResult /*UserViewData*/ Login([FromBody] LoginData login_data)
    {
        var item = _context.User.FirstOrDefault(t => t.Username == login_data.Username || t.Email == login_data.Email);

        if (item != null)
        {
            var last_login_attempt = item.LastLoginAttempt;
            item.LastLoginAttempt = DateTime.Now;
            _context.Update(item);
            _context.SaveChanges();
            if (login_data.Password != null && (last_login_attempt != null || (DateTime.Now - last_login_attempt).TotalSeconds > 3))
            {
                if (PasswordHasher.CheckHash(login_data.Password, new PasswordAndSalt()
                {
                    PasswordHash = item.PasswordHash, PasswordSalt = item.PasswordSalt
                }))
                {
                    HttpContext.Login <LoggableEntities, User>(env, _context, "User", item, new LoggableEntities()
                    {
                        User = item
                    });

                    return(Ok(UserViewData.FromUser(item)));
                }
            }
        }
        return(Unauthorized());
    }
Example #9
0
    public UserViewData Register([FromBody] RegistrationData registration_data)
    {
        string username           = registration_data.Username,
               email              = registration_data.Email,
               email_confirmation = registration_data.EmailConfirmation;

        if (username != null && username != "" && email != null && email != "" && email == email_confirmation)
        {
            var item = _context.User.FirstOrDefault(t => t.Username == username || t.Email == email);
            if (item == null)
            {
                var new_password_text = PasswordHasher.RandomPassword;
                var new_password      = PasswordHasher.Hash(new_password_text);
                item = new User()
                {
                    Id = _context.User.Max(i => i.Id) + 1, Username = username, Email = email, PasswordHash = new_password.PasswordHash, PasswordSalt = new_password.PasswordSalt
                };
                var apiKey           = StaticMailer._mailOptions.MailApiToken;
                var client           = new SendGridClient(apiKey);
                var from             = new EmailAddress(StaticMailer._mailOptions.MailFrom);
                var subject          = "User account created with temporary password.";
                var to               = new EmailAddress(item.Email);
                var plainTextContent = $"Your User temporary password has set. Your username and password combination is \n\nUsername: {item.Username}\nPassword: {new_password_text}\n";
                var htmlContent      = $"Your User temporary password has set. Your username and password combination is <br />Username: {item.Username}<br />Password: {new_password_text}<br />";
                var msg              = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
                var response         = client.SendEmailAsync(msg).Result;

                _context.User.Add(item);
                _context.SaveChanges();

                return(UserViewData.FromUser(item));
            }
        }
        throw new Exception("Cannot register.");
    }
Example #10
0
        /// <summary>
        /// Minimum requirements:
        ///     To Add State Ship Director
        ///         #) Admin must be CMS Admin
        ///     To Add a State Admin
        ///         #) Admin must be Ship Director or State Admin PLUS with Approver Delegate rights
        ///     To Add a State User
        ///         #) Admin must be minimum of a State Admin
        /// </summary>
        /// <param name="AdminData"></param>
        /// <param name="StateFIPS"></param>
        /// <param name="NewUserRoleIsAdmin"></param>
        /// <returns></returns>
        public static bool CanAddUserToStateRole(UserViewData AdminData, string StateFIPS, bool NewUserRoleIsAdmin, bool ShipDirectorRoleRequested)
        {
            //CMS Admins can create users of all state roles
            if (AdminData.IsCMSAdmin)
            {
                return(true);
            }
            else
            {
                //Ship directors are also state admins
                if (AdminData.IsStateAdmin && (AdminData.StateFIPS == StateFIPS))
                {
                    //Ship directors can only be created by CMS Admins
                    if (ShipDirectorRoleRequested)
                    {
                        return(false);
                    }

                    //If State Admin is requested, creating Admin must be State Admin PLUS Approver [or Ship Director]
                    if (NewUserRoleIsAdmin)
                    {
                        return(AdminData.IsShipDirector || AdminData.IsStateApproverDesignate);
                    }
                    else
                    {
                        //New State User Role requests can be served by State Admins
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #11
0
        public static bool DenyUser(UserViewData UserData, int ApproverId, out string ErrorMessage)
        {
            //using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
            //{
            string FailureReason;

            if (UserBLL.DeleteUser(UserData.UserId, out FailureReason))
            {
                if (SendDisapproveEmail(UserData))
                {
                    //scope.Complete();
                    ErrorMessage = string.Empty;
                    return(true);
                }
                else
                {
                    ErrorMessage = "Attempt to send email notification to the User failed. Please try later.";
                    return(false);
                }
            }
            else
            {
                //This is old message. After we introduced Failure reason, we have not changed the message.
                ErrorMessage = "Deny process failed. Please try later or contact support if this issue persists.";
                return(false);
            }
            //}
        }
Example #12
0
        //private string GetStateFIPSForNewUser()
        //{
        //    string StateFIPS = string.Empty;

        //    if (this.AccountInfo.IsStateLevel)
        //        StateFIPS = this.AccountInfo.StateFIPS;
        //    else if(this.AccountInfo.IsCMSLevel)
        //    {
        //        var ddlStatesObj = formView.FindControl("ddlStates") as DropDownList;
        //        if (ShowStateSelection && (ddlStatesObj.SelectedValue.Trim() != string.Empty))
        //            StateFIPS = ddlStatesObj.SelectedValue.Trim();
        //    }

        //    return StateFIPS;
        //}


        private void InitializeView()
        {
            if (!IsPostBack)
            {
                PopulatePresentorState();
            }

            UserViewData = new UserViewData();
        }
Example #13
0
        private static bool CanEditMultiSubStateUser(UserViewData SubStateUserData, UserViewData EditorData)
        {
            if (EditorData.IsCMSLevel)
            {
                return(EditorData.IsCMSAdmin);
            }
            else //State Level Users follow
            {
                //Kick out other state users
                if ((EditorData.StateFIPS != SubStateUserData.StateFIPS))
                {
                    return(false);
                }

                //State Scope Users must be Admins
                if (EditorData.Scope.IsEqual(Scope.State))
                {
                    return(EditorData.IsStateAdmin);
                }

                //Kickout agency users.
                if (EditorData.Scope.IsEqual(Scope.Agency))
                {
                    return(false);
                }

                //The only possibility from now on, is Editor is also a  Sub State Scope user..
                IEnumerable <UserRegionalAccessProfile> EditorAdminProfiles = EditorData.RegionalProfiles.Where(p => p.IsAdmin == true);

                //Iterate each Admin profile of Editor
                foreach (UserRegionalAccessProfile editorUserProfile in EditorAdminProfiles)
                {
                    //For each maching sub state of editor/substate user
                    foreach (UserRegionalAccessProfile subStateUserProfile in SubStateUserData.RegionalProfiles.Where(p => p.RegionId == editorUserProfile.RegionId))
                    {
                        //Sub State Approvers can be edited by state approvers or state admins only.
                        if (!subStateUserProfile.IsApproverDesignate)
                        {
                            //sub state admins can be edited by same sub state approvers
                            if (subStateUserProfile.IsAdmin && editorUserProfile.IsApproverDesignate)
                            {
                                return(true);
                            }
                            else if (!subStateUserProfile.IsAdmin)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }


            return(false);
        }
Example #14
0
 private static bool CanEditCMSUser(UserViewData CMSUserData, UserViewData EditorData)
 {
     if (CMSUserData.IsCMSAdmin)
     {
         return(EditorData.IsCMSAdmin && EditorData.IsCMSApproverDesignate);
     }
     else
     {
         return(EditorData.IsCMSAdmin);
     }
 }
Example #15
0
 /// <summary>
 /// To Add CMS Admins
 /// #) CMS Admins can add Users at CMS Scope
 /// #) CMS Admin must be approver delegate to add a CMS Admin.
 /// </summary>
 /// <param name="AdminData"></param>
 /// <param name="NewUserRoleIsAdmin"></param>
 /// <returns></returns>
 public static bool CanAddUserToCMSRole(UserViewData AdminData, bool NewUserRoleIsAdmin)
 {
     if (NewUserRoleIsAdmin)
     {
         return(AdminData.IsCMSAdmin && AdminData.IsCMSApproverDesignate);
     }
     else
     {
         return(AdminData.IsCMSAdmin);
     }
 }
Example #16
0
        /// <summary>
        /// To avoid the Business Object refer back to UserBLL, we would like to do the processing here,
        /// rather than User.cs where mapping is done.
        /// </summary>
        /// <param name="viewData"></param>
        /// <param name="accountInfo"></param>
        private static void StepUpViewData(ref UserViewData viewData)
        {
            string description = string.Empty;
            string title       = string.Empty;
            //bool IsShipDirector = false;
            //Get the Role that match user account information

            Role r = LookupBLL.GetRole(viewData.Scope, viewData.IsAdmin);

            title = r.Name;

            //Set special description for Ship Director.
            if (r.IsStateAdmin)
            {
                //IsShipDirector = LookupBLL.IsShipDirector(viewData.UserId, viewData.StateFIPS);
                if (viewData.IsShipDirector)
                {
                    description = "State SHIP Director";
                    title       = "Ship Director";
                }
            }

            //Set descriptors here for State/CMS. Other Users have it in their UserRegionalProfiles.
            if (r.scope.IsEqual(Scope.State) || r.scope.IsEqual(Scope.CMS))
            {
                viewData.DescriptorIds = GetDescriptorsForUser(viewData.UserId, Constants.Defaults.DefaultValues.AgencyIdForNonAgencyUsers);
            }

            //Add Supervisor data for State and CMS level users.
            if (viewData.IsUserStateScope)
            {
                var reviewers = UserBLL.GetReviewersForUser(viewData.UserId, null);
                if (reviewers != null && reviewers.Count() > 0)
                {
                    viewData.SupervisorIdForStateUser   = reviewers.First().Key;
                    viewData.SupervisorNameForStateUser = reviewers.First().Value;
                }
            }

            description = (description == string.Empty) ? r.Description : description;


            if (viewData.RegionalProfiles != null)
            {
                viewData.RegionalProfiles.ForEach(prof => prof.RegionScope = (Scope?)r.scope);
            }


            viewData.RoleDescription = description;
            viewData.RoleTitle       = title;
            //viewData.IsShipDirector = IsShipDirector;
        }
Example #17
0
        /// <summary>
        /// Get the list of the users.
        /// </summary>
        /// <returns>action user</returns>
        public async Task <ActionResult> GetUsers()
        {
            UserViewData userViewData = new UserViewData {
                Users = new List <UserItemData>()
            };
            UserResultData result = await WebApiClient.GetAsync <UserResultData>(Constant.WebApiControllerUser, Constant.WebApiUserList);

            if (result.OperationSuccess && result.UserDtoList != null)
            {
                userViewData.Users = result.UserDtoList;
            }
            return(PartialView("Partials/_UsersList", userViewData));
        }
Example #18
0
 private static bool CanViewCMSUser(UserViewData CMSUserData, UserViewData ViewerData)
 {
     //CMSAdmins can be viewed by other CMSAdmins.
     if (CMSUserData.IsCMSAdmin)
     {
         return(ViewerData.IsCMSAdmin);
     }
     else
     //CMSUsers can be viewed by both CMSAdmins and CMSUsers.
     {
         return(ViewerData.IsUserCMSScope);
     }
 }
Example #19
0
        /// <summary>
        /// To add User to State Scope
        /// #) User must be CMS Admin Or
        /// #) User must be minimum of State Admin if not ship director
        /// #) States must match if Admin is State Admin or Ship Director
        /// </summary>
        /// <param name="AdminData"></param>
        /// <param name="StateFIPS"></param>
        /// <returns></returns>
        private static bool CanAddUserToStateScope(UserViewData AdminData, string StateFIPS)
        {
            if (AdminData.IsStateAdmin && AdminData.StateFIPS == StateFIPS)
            {
                return(true);
            }
            else if (AdminData.IsCMSAdmin)
            {
                return(true);
            }

            return(false);
        }
Example #20
0
        //this UserId is passed is the RegisteredUserId/requester UserId
        private static bool SendApprovedEmail(int UserId, string uniqueId)
        {
            UserViewData userView = UserBLL.GetUser(UserId);

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            sb.AppendFormat("Dear {0},", userView.FullName);
            sb.AddNewHtmlLines(2);
            sb.Append("Your request for a CMS SHIP Unique ID has been approved.");
            sb.AddNewHtmlLines(2);

            //sammit: new business rule do not show the unique ID in the e-mail
            //sb.Append("Your CMS SHIP Unique ID is: " + uniqueId);
            //sb.AddNewHtmlLines(2);

            sb.Append("You may login anytime to the SHIPtalk website and find 'CMS SHIP Unique ID' under 'My Profile'.");
            sb.AddNewHtmlLines(2);

            sb.Append("Note: The Unique ID will not be recognized by Customer Services Representatives until the 1st week of the following month.");
            sb.AddNewHtmlLines(2);

            sb.Append("Thank you,");
            sb.AddNewHtmlLine();

            sb.Append("SHIP NPR Help Desk");
            sb.AddNewHtmlLine();

            sb.Append("<a href='https://shipnpr.shiptalk.org'>https://shipnpr.shiptalk.org</a>");
            sb.AddNewHtmlLine();
            sb.Append(ConfigUtil.ShiptalkSupportPhone);
            sb.AddNewHtmlLines(5);


            ShiptalkMailMessage mailMessage = new ShiptalkMailMessage(true, ShiptalkMailMessage.MailFrom.ShiptalkResourceCenter);

            mailMessage.ToList.Add(userView.PrimaryEmail);
            mailMessage.Subject = "Your SHIPtalk.org request for CMS SHIP Unique ID";

            mailMessage.Body = sb.ToString();
            ShiptalkMail mail = new ShiptalkMail(mailMessage);


            try
            {
                mail.SendMail();
                return(true);
            }
            catch { }

            return(false);
        }
Example #21
0
        bool IAuthorize.IsAuthorized()
        {
            //TODO: Need to make sure User is Counselor, Data Submitter, IsSuperEditor, ShipDirector, CMS Admin, Reviewer
            UserViewData UserData = UserBLL.GetUser(AccountInfo.UserId);

            if (UserData.IsStateLevel)
            {
                int CounselorDescriptorId = Descriptor.Counselor.EnumValue <int>();
                int SubmitterDescriptorId = Descriptor.DataSubmitter.EnumValue <int>();
                int EditorDescriptorId    = Descriptor.DataEditor_Reviewer.EnumValue <int>();

                //State Users need to be either ShipDirector, StateSuperEditor or have one of the Descriptors.
                if (UserData.IsUserStateScope)
                {
                    //Check ShipDirector or StateSuperEditor
                    if (UserData.IsShipDirector || UserData.IsStateSuperDataEditor)
                    {
                        return(true);
                    }

                    //Check Descriptors
                    var DescriptorIdsForStateUser = UserData.DescriptorIds;
                    return(DescriptorIdsForStateUser.Contains(CounselorDescriptorId) || DescriptorIdsForStateUser.Contains(SubmitterDescriptorId) ||
                           DescriptorIdsForStateUser.Contains(EditorDescriptorId));
                }
                else if (UserData.IsUserSubStateRegionalScope || UserData.IsUserAgencyScope)
                {
                    var superEditors = UserData.RegionalProfiles.Where(sup => sup.IsSuperDataEditor == true);
                    if (superEditors != null && superEditors.Count() > 0)
                    {
                        return(true);
                    }

                    var DescriptorIdsForStateUser = UserData.RegionalProfiles.Where(prof => prof.DescriptorIDList != null && (
                                                                                        prof.DescriptorIDList.Contains(CounselorDescriptorId) ||
                                                                                        prof.DescriptorIDList.Contains(SubmitterDescriptorId) ||
                                                                                        prof.DescriptorIDList.Contains(EditorDescriptorId)
                                                                                        )
                                                                                    );

                    return(DescriptorIdsForStateUser != null && DescriptorIdsForStateUser.Count() > 0);
                }
            }
            else
            {
                return(UserData.IsCMSLevel);
            }

            return(false);
        }
Example #22
0
        /// <summary>
        /// Is Approver at CMS or State or atleast one of the agencies/regions.
        /// </summary>
        /// <param name="AccountInfo"></param>
        /// <returns></returns>
        public static bool IsApprover(UserAccount AccountInfo)
        {
            //All Admins are Default Admins at their Scope Level.
            //However, for State Level, Ship Directors are Default Admins.
            if (AccountInfo.IsCMSLevel)
            {
                if (AccountInfo.IsAdmin && AccountInfo.IsCMSScope)
                {
                    if (AccountInfo.IsApproverDesignate.HasValue)
                    {
                        return(AccountInfo.IsApproverDesignate.Value);
                    }
                }
                return(false);
            }
            else if (AccountInfo.IsStateScope)
            {
                if (AccountInfo.IsShipDirector)
                {
                    return(true);
                }
                else
                {
                    if (AccountInfo.IsApproverDesignate.HasValue)
                    {
                        return(AccountInfo.IsApproverDesignate.Value);
                    }

                    return(false);
                }
            }
            else
            {
                //For potential multi Regional Users such as Sub State and Agency Users
                //Atleast at one agency, they are admin. Thats all we can do for generalized IsAdmin search.
                //For regional specific IsAdmin, this method must not be used.
                UserViewData UserData = UserBLL.GetUser(AccountInfo.UserId);
                foreach (UserRegionalAccessProfile regionalProfile in UserData.RegionalProfiles)
                {
                    if (regionalProfile.IsApproverDesignate && regionalProfile.IsAdmin)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #23
0
        private static bool SendApprovedEmail(int UserId)
        {
            UserViewData userView = UserBLL.GetUser(UserId);

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            sb.AppendFormat("Dear {0},", userView.FullName);
            sb.AddNewHtmlLines(2);
            sb.Append("Your request to shipnpr.shiptalk.org account has been approved.");
            sb.AddNewHtmlLines(2);
            sb.Append("You may login anytime using your registered information.");
            sb.AddNewHtmlLines(2);

            sb.Append("If you do not know your new SHIPtalk password, you can reset it by going to <a href='https://shipnpr.shiptalk.org'>https://shipnpr.shiptalk.org</a> and clicking 'Forgot password?' in the left of the screen. Follow the instructions to have the password reset instructions emailed to you. Once you reset your password, you should be able to log in to the website with your username (email address) and new password.");
            sb.AddNewHtmlLines(2);

            sb.Append("Submit your entire email address so the instructions to reset your password will be emailed to you.");
            sb.AddNewHtmlLine();

            sb.Append("Thank you,");
            sb.AddNewHtmlLine();
            sb.Append("SHIP NPR Help Desk");
            sb.AddNewHtmlLine();
            sb.Append("<a href='https://shipnpr.shiptalk.org'>https://shipnpr.shiptalk.org</a>");
            sb.AddNewHtmlLine();
            sb.Append(ConfigUtil.ShiptalkSupportPhone);
            sb.AddNewHtmlLines(5);



            ShiptalkMailMessage mailMessage = new ShiptalkMailMessage(true, ShiptalkMailMessage.MailFrom.ShiptalkResourceCenter);

            mailMessage.ToList.Add(userView.PrimaryEmail);
            mailMessage.Subject = "Your shipnpr.shiptalk.org account is approved";

            mailMessage.Body = sb.ToString();
            ShiptalkMail mail = new ShiptalkMail(mailMessage);


            try
            {
                mail.SendMail();
                return(true);
            }
            catch { }

            return(false);
        }
Example #24
0
        public ActionResult Edit(UserViewData userViewData)
        {
            if (!ModelState.IsValid)
            {
                return(View(userViewData));
            }

            var user = userViewData.GetUser();

            using (var session = PersistenceHelper.OpenSession())
            {
                var userRepository = new UserRepository(session);
                userRepository.CreateOrUpdate(user);
            }

            return(RedirectToAction("Index"));
        }
Example #25
0
        private static bool SendRevokeEmail(int RegisteredUserId)
        {
            UserViewData userView = UserBLL.GetUser(RegisteredUserId);

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            sb.AppendFormat("Dear {0},", userView.FullName);
            sb.AddNewHtmlLines(2);
            sb.Append("Your CMS SHIP Unique ID has been revoked by the State SHIP Director or by the Administrator.");
            sb.AddNewHtmlLines(2);

            sb.Append("If you feel that your CMS SHIP Unique ID account has been deleted in error, please contact your State SHIP Director.");
            sb.AddNewHtmlLines(2);

            sb.Append("Thank you,");
            sb.AddNewHtmlLine();

            sb.Append("SHIP NPR Help Desk");
            sb.AddNewHtmlLine();

            sb.Append("<a href='https://shipnpr.shiptalk.org'>https://shipnpr.shiptalk.org</a>");
            sb.AddNewHtmlLine();
            sb.Append(ConfigUtil.ShiptalkSupportPhone);
            sb.AddNewHtmlLines(5);


            ShiptalkMailMessage mailMessage = new ShiptalkMailMessage(true, ShiptalkMailMessage.MailFrom.ShiptalkResourceCenter);

            mailMessage.ToList.Add(userView.PrimaryEmail);
            mailMessage.Subject = "Your SHIPtalk.org request for CMS SHIP Unique ID is revoked.";

            mailMessage.Body = sb.ToString();
            ShiptalkMail mail = new ShiptalkMail(mailMessage);


            try
            {
                mail.SendMail();
                return(true);
            }
            catch { }

            return(false);
        }
Example #26
0
        private UserProfile GetChangedUserProfile(UserViewData ChangedData)
        {
            UserProfile profile = new UserProfile();

            profile.UserId     = UserIdOfProfileToEdit;
            profile.FirstName  = ChangedData.FirstName;
            profile.MiddleName = ChangedData.MiddleName;
            profile.LastName   = ChangedData.LastName;
            profile.NickName   = ChangedData.NickName;
            profile.Suffix     = ChangedData.Suffix;
            profile.Honorifics = ChangedData.Honorifics;

            profile.SecondaryEmail = ChangedData.SecondaryEmail;
            profile.PrimaryPhone   = ChangedData.PrimaryPhone;
            profile.SecondaryPhone = ChangedData.SecondaryPhone;
            profile.IsActive       = IsActiveUser;

            return(profile);
        }
Example #27
0
        private static bool SendUserAboutEmailChangeRequest(int UserId, out string ErrorMessage)
        {
            ErrorMessage = string.Empty;
            UserViewData UserRegistrationData = UserBLL.GetUser(UserId);

            ShiptalkMailMessage mailMessage = new ShiptalkMailMessage(true, ShiptalkMailMessage.MailFrom.ShiptalkResourceCenter);

            mailMessage.ToList.Add(UserRegistrationData.PrimaryEmail);
            mailMessage.Subject = "Your shipnpr.shiptalk.org Email Change request";

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.AppendFormat("Dear {0} {1},", UserRegistrationData.FirstName.ToCamelCasing(), UserRegistrationData.LastName.ToCamelCasing());
            sb.AddNewHtmlLines(2);
            sb.Append("You have requested to change your Email at shipnpr.shiptalk.org.");
            sb.AddNewHtmlLines(2);
            sb.Append("The Verification email has been sent to your new email id. Please check the email and follow the instructions to verify your email address. You can continue using Shipnpr website with your old email id until the new email id is being verified.");
            sb.AddNewHtmlLines(2);
            sb.Append("If you have not requested for Email change, please contact SHIP NPR Help Desk at 1-800-253-7154, option 1 or <a href='mailto:[email protected]'>[email protected]</a> immediately.");
            sb.AddNewHtmlLines(3);
            sb.Append("Thank you,");
            sb.AddNewHtmlLines(2);
            sb.Append("SHIP NPR Help Desk");
            sb.AddNewHtmlLine();
            sb.Append(ConfigUtil.ShiptalkSupportPhone);
            sb.AddNewHtmlLine();
            sb.Append(ConfigUtil.EmailOfResourceCenter);
            sb.AddNewHtmlLines(5);

            mailMessage.Body = sb.ToString();
            ShiptalkMail mail = new ShiptalkMail(mailMessage);

            if (!mail.SendMail())
            {
                ErrorMessage = string.Format("An error occured while sending email to {0}.", UserRegistrationData.PrimaryEmail);
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #28
0
        private static bool CanAddUserToAgencyScope(UserViewData AdminData, string StateFIPS)
        {
            //CMS Admins can create users of all state roles
            if (AdminData.IsCMSAdmin)
            {
                return(true);
            }
            else if (AdminData.StateFIPS == StateFIPS)
            {
                if (AdminData.IsStateAdmin)
                {
                    return(true);
                }
                else if (AdminData.IsUserSubStateRegionalScope)
                {
                    //Admin is a Sub State User.
                    foreach (UserRegionalAccessProfile subStateUserProfile in AdminData.RegionalProfiles)
                    {
                        if (subStateUserProfile.IsAdmin)
                        {
                            return(true);
                        }
                    }
                }
                else if (AdminData.IsUserSubStateRegionalScope)
                {
                    //Admin is an agency user.
                    foreach (UserRegionalAccessProfile agencyUserProfile in AdminData.RegionalProfiles)
                    {
                        if (agencyUserProfile.IsAdmin)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Example #29
0
        private string GetUserInfo(int UserId)
        {
            UserViewData UserData = UserBLL.GetUser(UserId);


            string fmt = "{0} : {1}</BR>";

            StringBuilder sb = new StringBuilder();

            //sb.AppendFormat(fmt, "UserId", UserData.UserId);
            sb.AppendFormat(fmt, "First Name", UserData.FirstName);
            sb.AppendFormat(fmt, "Middle Name", UserData.MiddleName);
            sb.AppendFormat(fmt, "Last Name", UserData.LastName);
            sb.AppendFormat(fmt, "Email", UserData.PrimaryEmail);
            sb.AppendFormat(fmt, "Primary Phone", UserData.PrimaryPhone);
            sb.AppendFormat(fmt, "Scope", UserData.Scope.Description());
            sb.AppendFormat(fmt, "IsAdmin", UserData.IsAdmin.ToString());
            sb.AppendFormat(fmt, "State", UserData.StateName);


            return(sb.ToString());
        }
Example #30
0
        private static bool EmailNotifyUniqueIDApprovers(int RequestedUserId)
        {
            //Prepare Mail Object
            ShiptalkMailMessage mailMessage = new ShiptalkMailMessage(true, ShiptalkMailMessage.MailFrom.ShiptalkResourceCenter);
            UserViewData        userData    = UserBLL.GetUser(RequestedUserId);

            var Approvers = GetApproversForUser(RequestedUserId);

            foreach (var approver in Approvers)
            {
                mailMessage.ToList.Add(approver.Value);
            }

            mailMessage.Subject = "New CMS SHIP Unique ID request";

            //PREPARE BODY OF EMAIL
            StringBuilder sbMailBody = new StringBuilder();

            sbMailBody.Append("A SHIP User has requested a new CMS SHIP Unique ID. Please login to <a href='https://shipnpr.shiptalk.org'>https://shipnpr.shiptalk.org</a> to respond the request.");
            sbMailBody.Append(" Go to the 'User' screen and click on 'Review, Approve, Deny CMS SHIP Unique ID Requests' to view and approve/deny this request.");
            sbMailBody.AddNewHtmlLines(3);
            sbMailBody.Append("A brief snapshot of the user profile is provided below:");
            sbMailBody.AddNewHtmlLines(2);
            sbMailBody.AppendFormat("Name: {0}{1} {2}", userData.FirstName,
                                    string.IsNullOrEmpty(userData.MiddleName) ? string.Empty : " " + userData.MiddleName,
                                    userData.LastName);
            sbMailBody.AddNewHtmlLine();
            sbMailBody.AppendFormat("Primary Email: {0}", userData.PrimaryEmail);
            sbMailBody.AddNewHtmlLine();
            sbMailBody.AppendFormat("Primary Phone: {0}", userData.PrimaryPhone);
            sbMailBody.AddNewHtmlLines(3);
            mailMessage.Body = sbMailBody.ToString();

            //Send Mail here
            ShiptalkMail mail = new ShiptalkMail(mailMessage);

            return(mail.SendMail());
        }