Exemple #1
0
        /// <summary>
        /// All The Methods That are used in coding
        /// </summary>

        #region Methods
        public void login()
        {
            Session["EndSubscriptionFlag"] = null;
            try
            {
                if (txtEmail.Text != "  " && txtPassword.Text != "")
                {
                    AuthenticateUser();

                    us_ID = Convert.ToInt32(Session["UserID"]);

                    if (us_ID > 0)
                    {
                        selectUserRole();
                        int             c_id              = Convert.ToInt32(Session["company_id"]);
                        ObjectParameter freeCount         = new ObjectParameter("free_count", typeof(int));
                        ObjectParameter subscriptionCount = new ObjectParameter("Subscription_count", typeof(int));

                        var r = context.sp_checklicense(c_id, us_ID, freeCount, subscriptionCount);

                        if (Convert.ToInt32(subscriptionCount.Value) > 0)
                        {
                            if (Convert.ToInt32(freeCount.Value) > 0)
                            {
                                string userData = string.Empty;
                                string role     = Convert.ToString(Session["Rolename"]);
                                if (role == "Sales Manager")
                                {
                                    userData = "Sales";
                                }
                                else if (role == "Purchase Manager")
                                {
                                    userData = "Purchase";
                                }
                                else if (role == "Manager" || role == "")
                                {
                                    userData = "Manager";
                                }
                                Session["UserRoleSession"] = userData;

                                if (!string.IsNullOrEmpty(userData))
                                {
                                    // create a new ticket used for authentication

                                    if (cbRemember.Checked == true)
                                    {
                                        Response.Cookies["us_ID"].Value    = txtEmail.Text;
                                        Response.Cookies["enPswd"].Value   = txtPassword.Text;
                                        Response.Cookies["us_ID"].Expires  = DateTime.Now.AddDays(15);
                                        Response.Cookies["enPswd"].Expires = DateTime.Now.AddDays(15);
                                    }

                                    else
                                    {
                                        Response.Cookies["us_ID"].Expires = DateTime.Now.AddDays(-1);

                                        Response.Cookies["enPswd"].Expires = DateTime.Now.AddDays(-1);
                                    }
                                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, txtEmail.Text, DateTime.Now, DateTime.Now.AddMinutes(15), false, userData, FormsAuthentication.FormsCookiePath);
                                    var encryptedTicket = FormsAuthentication.Encrypt(ticket);
                                    if (cbRemember.Checked)
                                    {
                                        HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                                        cookie.Expires = ticket.Expiration;
                                        HttpContext.Current.Response.Cookies.Set(cookie);
                                    }
                                    else
                                    {
                                        FormsAuthentication.SetAuthCookie(txtEmail.Text, false);
                                    }
                                }

                                string returnUrl = Request.QueryString["ReturnUrl"];
                                if (role.Equals("Purchase Manager"))
                                {
                                    returnUrl = "Purchases/Purchase.aspx";
                                }
                                else if (role == "Sales Manager")
                                {
                                    returnUrl = "Sales/Sale.aspx";
                                }
                                else if (role == "Manager" || role == "")
                                {
                                    returnUrl = "Home.aspx";
                                }
                                Response.Redirect(@"~/" + returnUrl, false);
                            }
                            else
                            {
                                ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('Your free count has over.');", true);
                                Session["CustomerId"] = txtEmail.Text;
                            }
                        }
                        else
                        {
                            ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('Your subscription has been ended, Please Choose any Of Our Plan To Continue.');", true);
                            Session["CustomerId"] = txtEmail.Text;
                        }
                    }

                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('User Name Or Password Is Invalid');", true);
                    }
                }


                else
                {
                    lblError.Visible = true;
                    lblError.Text    = "Please Enter Your Email ID and Password";
                }
            }
            catch (Exception ex)
            {
                ErrorLog.saveerror(ex);
            }
        }