Beispiel #1
0
 /// <summary>
 /// Updates the session variables with logged in user data
 /// </summary>
 /// <param name="user">The logged in user</param>
 public static void SetUserSessionData(StageBitz.Data.User user)
 {
     UserID        = user.UserId;
     LoginName     = user.LoginName;
     UserFirstName = user.FirstName;
     UserLastName  = user.LastName;
 }
Beispiel #2
0
        /// <summary>
        /// Handles the ServerValidate event of the cusvalCurrentPassword control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="args">The <see cref="ServerValidateEventArgs"/> instance containing the event data.</param>
        protected void cusvalCurrentPassword_ServerValidate(object source, ServerValidateEventArgs args)
        {
            string currentPasswordHash = Utils.HashPassword(txtCurrentPassword.Text);

            StageBitz.Data.User user = DataContext.Users.Where(u => u.UserId == UserID && u.Password == currentPasswordHash).FirstOrDefault();

            args.IsValid = (user != null);
        }
Beispiel #3
0
        /// <summary>
        /// Handles the DeleteCommand event of the rgProjectTeam control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridCommandEventArgs"/> instance containing the event data.</param>
        protected void rgProjectTeam_DeleteCommand(object sender, GridCommandEventArgs e)
        {
            searchUsers.HideNotifications();

            GridDataItem dataItem = (GridDataItem)e.Item;

            int projectUserId = (int)dataItem.GetDataKeyValue("ProjectUserId");

            if (projectUserId > 0)
            {
                ProjectUser projectuser = this.GetBL <ProjectBL>().GetProjectUser(projectUserId);

                #region Project Notification

                string projectUserName = (projectuser.User.FirstName + " " + projectuser.User.LastName).Trim();
                this.GetBL <NotificationBL>().AddNotification(CreateNotification(Support.GetCodeIdByCodeValue("OperationType", "DELETE"), string.Format("{0} removed {1} from the project team.", Support.UserFullName, projectUserName)), false);
                //DataContext.Notifications.AddObject();

                #endregion Project Notification

                //Update Project Daily Usage Summary
                //ProjectUsageHandler.UpdateProjectUsage(projectuser.Project, UserID, projectuser.UserId, true, Today, DataContext);

                DataContext.ProjectUsers.DeleteObject(projectuser);
            }
            else
            {
                int        invitationId = (int)dataItem.GetDataKeyValue("InvitationId");
                Invitation invitation   = DataContext.Invitations.Where(inv => inv.InvitationId == invitationId).FirstOrDefault();

                #region Project Notification

                string invitedUserName = string.Empty;

                if (invitation.ToUserId == null)
                {
                    invitedUserName = invitation.ToName;
                }
                else
                {
                    StageBitz.Data.User invitedUser = DataContext.Users.Where(u => u.UserId == invitation.ToUserId).FirstOrDefault();
                    invitedUserName = (invitedUser.FirstName + " " + invitedUser.LastName).Trim();
                }

                DataContext.Notifications.AddObject(CreateNotification(Support.GetCodeIdByCodeValue("OperationType", "DELETE"), string.Format("{0} removed the project invitation for {1}.", Support.UserFullName, invitedUserName)));

                #endregion Project Notification

                DataContext.DeleteInvitation(invitation.InvitationId);
            }

            DataContext.SaveChanges();
            LoadProjectTeam();
        }
Beispiel #4
0
        /// <summary>
        /// Tries to initialize the user session using the asp.net authentication cookie.
        /// If authentication cookie is unavailable, user is logged out forcefully.
        /// </summary>
        private static void InitializeUserSessionFromAuthCookie()
        {
            bool isAuthenticated = false;

            //User must be re-authenticated and the session must be reinitialized

            //If remember me cookie is available, setup the session automaitcally by
            //requesting user details from the DB.
            //If the cookie is unavailable, perform a forced Logout.
            try
            {
                HttpCookie authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];

                if (authCookie != null)
                {
                    //We are storing the user ID as the username inside asp.net auth cookie (See Login.aspx).
                    //Check whether we can find it inside the cookie.
                    string cookieUserName   = FormsAuthentication.Decrypt(authCookie.Value).Name;
                    int    rememberedUserID = 0;
                    int.TryParse(cookieUserName, out rememberedUserID);

                    if (rememberedUserID > 0)
                    {
                        //If a remembered user ID exists, get user details from the DB
                        using (StageBitzDB dataContext = new StageBitzDB())
                        {
                            StageBitz.Data.User user = GetActiveUserById(rememberedUserID, dataContext);

                            if (user != null)
                            {
                                //If authentication is successful, set the session variables
                                isAuthenticated = true;
                                SetUserSessionData(user);
                            }
                        }
                    }
                }
            }
            catch
            {
                HttpContext.Current.Response.Redirect("~/Account/Logout.aspx", true);
            }

            //If all attempts to authenticate the user has failed, perform a forced logout
            if (!isAuthenticated)
            {
                HttpContext.Current.Response.Redirect("~/Account/Logout.aspx", true);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Handles the Click event of the btnUpdatePassword control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnUpdatePassword_Click(object sender, EventArgs e)
        {
            if (!StopProcessing)
            {
                Page.Validate("changePasswordFields");
                if (!Page.IsValid)
                {
                    txtCurrentPassword.Text = string.Empty;
                    txtNewPassword.Text     = string.Empty;
                    txtConfirmPassword.Text = string.Empty;
                    return;
                }

                string currentPasswordHash = Utils.HashPassword(txtCurrentPassword.Text);
                string newPassword         = txtNewPassword.Text;

                if (!string.IsNullOrEmpty(newPassword))
                {
                    StageBitz.Data.User user = DataContext.Users.Where(u => u.UserId == UserID && u.Password == currentPasswordHash).FirstOrDefault();

                    if (user == null) //Invalid password
                    {
                    }
                    else
                    {
                        user.Password = Utils.HashPassword(newPassword);
                        DataContext.SaveChanges();

                        txtCurrentPassword.Text = string.Empty;
                        txtNewPassword.Text     = string.Empty;
                        txtConfirmPassword.Text = string.Empty;

                        ShowNotification("passwordUpdatedNotice");
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Loads the data.
        /// </summary>
        public void LoadData()
        {
            StageBitz.Data.Project project = DataContext.Projects.Where(p => p.ProjectId == ProjectID).FirstOrDefault();
            bool paymentsSpecified         = (FinanceSupport.GetCreditCardToken("Company", project.CompanyId) != null);

            ProjectStatusHandler.ProjectWarningInfo warningInfo = ProjectStatusHandler.GetProjectWarningStatus(project.ProjectStatusCodeId, project.ProjectTypeCodeId == Support.GetCodeByValue("ProjectType", "FREETRIALOPTIN").CodeId, project.ExpirationDate);
            StageBitz.Data.User companyAdmin = this.GetBL <CompanyBL>().GetCompanyPrimaryAdministrator(project.CompanyId);

            ProjectName       = Support.TruncateString(project.ProjectName, 30);
            RemainingDays     = string.Format("{0} day{1}", warningInfo.DaysToExpiration < 0 ? 0 : warningInfo.DaysToExpiration, warningInfo.DaysToExpiration == 1 ? string.Empty : "s");
            CompanyAdminName  = Support.TruncateString((companyAdmin.FirstName + " " + companyAdmin.LastName).Trim(), 30);
            CompanyAdminEmail = companyAdmin.Email1;
            PaymentFailedDate = null;

            CompanyFinancialUrl = ResolveUrl(string.Format("~/Company/CompanyFinancialDetails.aspx?companyid={0}", project.CompanyId));

            if (warningInfo.WarningStatus == ProjectStatusHandler.ProjectWarningStatus.NoWarning)
            {
                noticesMultiView.Visible = false;
                return;
            }
            else
            {
                noticesMultiView.Visible = true;
            }

            #region Determine User Permission Type

            ProjectPermission userType = ProjectPermission.Staff;
            if (Support.IsCompanyAdministrator(project.CompanyId))
            {
                userType = ProjectPermission.CompanyAdministrator;
            }
            else if (Support.IsProjectAdministrator(ProjectID))
            {
                userType = ProjectPermission.ProjectAdministrator;
            }
            else
            {
                userType = ProjectPermission.Staff;
            }

            #endregion Determine User Permission Type

            switch (warningInfo.WarningStatus)
            {
            case ProjectStatusHandler.ProjectWarningStatus.FreeTrialGrace:
                if (userType == ProjectPermission.CompanyAdministrator)
                {
                    noticesMultiView.ActiveViewIndex = (int)NoticeType.FreeTrialGraceCompanyAdmin;
                }
                break;

            case ProjectStatusHandler.ProjectWarningStatus.GracePeriod:
                if (userType == ProjectPermission.CompanyAdministrator)
                {
                    noticesMultiView.ActiveViewIndex = (int)NoticeType.GracePeriodCompanyAdmin;
                    ucCompanyPaymentFailedWarningGracePeriodCompanyAdmin.CompanyID = project.CompanyId;
                    ucCompanyPaymentFailedWarningGracePeriodCompanyAdmin.LoadData(CompanyPaymentFailedWarning.PermissionLevel.CompanyAdministrator,
                                                                                  CompanyPaymentFailedWarning.DisplayMode.PaymentFailedGracePeriod);
                }
                else if (userType == ProjectPermission.ProjectAdministrator)
                {
                    noticesMultiView.ActiveViewIndex = (int)NoticeType.GracePeriodProjectAdmin;
                    ucCompanyPaymentFailedWarningGracePeriodNonCompanyAdmin.CompanyID = project.CompanyId;
                    ucCompanyPaymentFailedWarningGracePeriodNonCompanyAdmin.LoadData(CompanyPaymentFailedWarning.PermissionLevel.NonCompanyAdministrator,
                                                                                     CompanyPaymentFailedWarning.DisplayMode.PaymentFailedGracePeriod);
                }
                PaymentFailedDate = project.ExpirationDate.Value.AddDays(-7);
                break;

            case ProjectStatusHandler.ProjectWarningStatus.PaymentFailed:
                if (userType == ProjectPermission.CompanyAdministrator)
                {
                    noticesMultiView.ActiveViewIndex = (int)NoticeType.PaymentFailedCompanyAdmin;
                    ucCompanyPaymentFailedWarningPaymentFailedCompanyAdmin.CompanyID = project.CompanyId;
                    ucCompanyPaymentFailedWarningPaymentFailedCompanyAdmin.LoadData(CompanyPaymentFailedWarning.PermissionLevel.CompanyAdministrator,
                                                                                    CompanyPaymentFailedWarning.DisplayMode.PaymentFailed);
                }
                else if (userType == ProjectPermission.ProjectAdministrator || userType == ProjectPermission.Staff)
                {
                    noticesMultiView.ActiveViewIndex = (int)NoticeType.PaymentFailedProjectStaff;
                    ucCompanyPaymentFailedWarningPaymentFailedNonCompanyAdmin.CompanyID = project.CompanyId;
                    ucCompanyPaymentFailedWarningPaymentFailedNonCompanyAdmin.LoadData(CompanyPaymentFailedWarning.PermissionLevel.NonCompanyAdministrator,
                                                                                       CompanyPaymentFailedWarning.DisplayMode.PaymentFailed);
                }

                break;

            case ProjectStatusHandler.ProjectWarningStatus.Suspended:
                if (userType == ProjectPermission.CompanyAdministrator)
                {
                    noticesMultiView.ActiveViewIndex = (int)NoticeType.SuspendedCompanyAdmin;
                }
                else if (userType == ProjectPermission.ProjectAdministrator || userType == ProjectPermission.Staff)
                {
                    noticesMultiView.ActiveViewIndex = (int)NoticeType.SuspendedProjectStaff;
                }
                break;

            case ProjectStatusHandler.ProjectWarningStatus.Closed:
                if (userType == ProjectPermission.CompanyAdministrator)
                {
                    noticesMultiView.ActiveViewIndex = (int)NoticeType.ClosedProjectCompanyAdmin;
                }
                break;
            }

            //If the project's payment has failed, calculate the number of days the payment is due.
            if (PaymentFailedDate != null)
            {
                int paymentOverdueDays = (int)(Today - PaymentFailedDate.Value).TotalDays;
                PaymentOverdueDays = string.Format("{0} day{1}", paymentOverdueDays, paymentOverdueDays == 1 ? string.Empty : "s");
            }

            upnlProjectWarningDisplay.Update();
        }
Beispiel #7
0
        public MobileInitialData AuthenticateUser(InitialRequestDetails userAuthenticationDetailsObj)
        {
            string status  = string.Empty;
            string message = string.Empty;

            MobileInitialData mobileInitialData = null;

            try
            {
                using (StageBitzDB dataContext = new StageBitzDB())
                {
                    bool isValidVersion = Helper.IsValidAppVersion(userAuthenticationDetailsObj.Version, out status);
                    if (isValidVersion)
                    {
                        string              passwordHash = Utils.HashPassword(userAuthenticationDetailsObj.Pwd);
                        PersonalBL          personalBL   = new PersonalBL(dataContext);
                        StageBitz.Data.User user         = personalBL.AuthenticateUser(userAuthenticationDetailsObj.Email, passwordHash);

                        if (user == null)
                        {
                            int pendingEmailTypeCodeId            = Utils.GetCodeByValue("EmailChangeRequestStatus", "PENDING").CodeId;
                            EmailChangeRequest emailChangeRequest = dataContext.EmailChangeRequests.Where(ec => ec.Email == userAuthenticationDetailsObj.Email && ec.StatusCode == pendingEmailTypeCodeId).FirstOrDefault();
                            if (emailChangeRequest != null)
                            {
                                //Check the password by getting the current active userID.
                                int userId = emailChangeRequest.UserId;
                                //If the PassWord is matched, we know that the user is valid where as he did not follow the link.
                                if (dataContext.Users.Where(u => u.UserId == userId && u.Password == passwordHash).FirstOrDefault() != null)
                                {
                                    // He has changed his Primary Email Address. However he has not activate it yet
                                    status  = "NOTOK";
                                    message = "Email updated please confirm.";
                                    goto FinalStatement;
                                }
                            }

                            //Invalid LogIn
                            status  = "NOTOK";
                            message = "Invalid Email address or Password.";
                        }
                        else
                        {
                            if (user.IsActive == true)
                            {
                                //Build the token
                                //Return Initializtion data
                                status = "OK";
                                byte[] content = Utils.EncryptStringAES(user.UserId.ToString());
                                mobileInitialData           = Helper.GetAllInitializeDataForUser(user.UserId);
                                mobileInitialData.UserToken = Utils.EncryptStringAES(user.UserId.ToString());
                            }
                            else
                            {
                                //User is not activated yet
                                status  = "NOTOK";
                                message = "Please activate your account.";
                            }
                        }
                    }
                    else
                    {
                        message = "Please update App.";
                    }
                }
            }
            catch (Exception ex)
            {
                AgentErrorLog.HandleException(ex);
                status  = "ERROR";
                message = "Oops! Unkown error. Sorry...";
            }
FinalStatement:
            if (mobileInitialData == null)
            {
                mobileInitialData = new MobileInitialData();
            }
            mobileInitialData.Status  = status;
            mobileInitialData.Message = message;
            return(mobileInitialData);
        }
Beispiel #8
0
        private void LoadData()
        {
            StageBitz.Data.Company company = DataContext.Companies.Where(c => c.CompanyId == CompanyId).FirstOrDefault();

            #region Header Details

            Support.AssignTextToLabel(lblCompanyName, company.CompanyName, 80);

            if (company.CreatedByUserId == null)
            {
                lblCreatedBy.Text = "System";
            }
            else
            {
                StageBitz.Data.User user = DataContext.Users.Where(u => u.UserId == company.CreatedByUserId).FirstOrDefault();
                string userFullName      = (user.FirstName + " " + user.LastName).Trim();

                Support.AssignTextToLabel(lblCreatedBy, userFullName, 80);
            }

            ltrlCreatedDate.Text = Support.FormatDate(company.CreatedDate);

            int invoiceFailedCodeId = Utils.GetCodeIdByCodeValue("InvoiceStatus", "FAILED");
            //Check if there any pending invoice exist
            int paymentFailedInvoiceCount = (from i in DataContext.Invoices
                                             join p in DataContext.Projects on i.RelatedID equals p.ProjectId
                                             where i.RelatedTableName == "Project" && i.InvoiceStatusCodeId == invoiceFailedCodeId && p.CompanyId == CompanyId
                                             select i).Count();

            if (paymentFailedInvoiceCount == 1)
            {
                imgPaymentError.Attributes.Add("Title", "There is a project with a payment failure.");
            }
            else if (paymentFailedInvoiceCount > 1)
            {
                imgPaymentError.Attributes.Add("Title", "There are projects with payment failures.");
            }
            else if (FinanceSupport.GetCreditCardToken("Company", CompanyId) == null)
            {
                imgPaymentError.Attributes.Add("Title", "Credit card details not provided.");
            }
            else
            {
                imgPaymentError.Visible = false;
            }
            #endregion

            #region Contact Details

            int truncateLength = 30;
            Support.AssignTextToLabel(lblAddressLine1, company.AddressLine1, truncateLength);
            Support.AssignTextToLabel(lblAddressLine2, company.AddressLine2, truncateLength);
            Support.AssignTextToLabel(lblCity, company.City, truncateLength);
            Support.AssignTextToLabel(lblState, company.State, truncateLength);
            Support.AssignTextToLabel(lblPostCode, company.PostCode, truncateLength);

            if (company.Country != null)
            {
                Support.AssignTextToLabel(lblCountry, company.Country.CountryName, truncateLength);
            }

            Support.AssignTextToLabel(lblPhone, company.Phone, truncateLength);
            Support.AssignTextToLabel(lblWebsite, company.Website, truncateLength);

            #endregion

            SetCompanySuspensionCheckBox();

            LoadCompanyAdministrators();
        }
Beispiel #9
0
        /// <summary>
        /// Handles the Click event of the btnSignIn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnSignIn_Click(object sender, EventArgs e)
        {
            if (!this.IsValid)
            {
                return;
            }

            //Hash the password and compare credentials with the DB
            string passwordHash = Utils.HashPassword(txtPassword.Text);
            string username     = txtUsername.Text;

            StageBitz.Data.User user = GetBL <PersonalBL>().AuthenticateUser(username, passwordHash);

            //Assign username and password to send activation email
            Email = username;

            if (user == null)
            {
                int pendingEmailTypeCodeId            = Support.GetCodeByValue("EmailChangeRequestStatus", "PENDING").CodeId;
                EmailChangeRequest emailChangeRequest =
                    GetBL <UtilityBL>().GetEmailChangeRequestsByUsernameAndEmailTypeCodeId(username, pendingEmailTypeCodeId);
                if (emailChangeRequest != null)
                {
                    //Check the password by getting the current active userID.
                    int userId = emailChangeRequest.UserId;
                    //If the PassWord is matched, we know that the user is valid where as he did not follow the link.
                    if (GetBL <PersonalBL>().GetUserByUserIdAndPasswordHash(userId, passwordHash) != null)
                    {
                        divActivationMailSentPrimaryEmailChange.Visible = true;
                        divPendingActivation.Visible  = false;
                        divInvalidLogin.Visible       = false;
                        divActivationMailSent.Visible = false;
                        txtPassword.Text         = string.Empty;
                        litPrimaryEmailSent.Text = username;
                        return;
                    }
                }
                divPendingActivation.Visible  = false;
                divInvalidLogin.Visible       = true;
                divActivationMailSent.Visible = false;
                divActivationMailSentPrimaryEmailChange.Visible = false;
                txtPassword.Text = string.Empty;
                txtUsername.Focus();
            }
            else
            {
                if (user.IsActive == true)
                {
                    Support.SetUserSessionData(user);

                    string cookieData = username + " " + passwordHash;

                    //Store the user id as the username inside asp.net auth cookie (if remember me is checked)
                    if (string.IsNullOrEmpty(InvitationCode))
                    {
                        FormsAuthentication.RedirectFromLoginPage(cookieData, chkRememberMe.Checked);
                    }
                    else
                    {
                        FormsAuthentication.SetAuthCookie(cookieData, chkRememberMe.Checked);
                        Response.Redirect("~/Default.aspx?invitationCode=" + InvitationCode);
                    }

                    //To Record the date where the user gets reset the session.
                    user.LastLoggedInDate = Now;
                    DataContext.SaveChanges();
                }
                else
                {
                    //User is not activated yet
                    divInvalidLogin.Visible = false;
                    divActivationMailSentPrimaryEmailChange.Visible = false;
                    divActivationMailSent.Visible = false;
                    divPendingActivation.Visible  = true;
                    txtPassword.Text            = string.Empty;
                    pendingActivationEmail.Text = user.Email1;
                    txtUsername.Focus();
                }
            }
        }