Exemplo n.º 1
0
        private void RedirectToReturnUrl()
        {
            var returnUrl = Request.QueryString["ReturnUrl"];

            if (!String.IsNullOrEmpty(returnUrl) && OpenAuth.IsLocalUrl(returnUrl))
            {
                Response.Redirect(returnUrl);
            }
            else
            {
                Response.Redirect("~/");
            }
        }
Exemplo n.º 2
0
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);



            string continueUrl = RegisterUser.ContinueDestinationPageUrl;

            if (!OpenAuth.IsLocalUrl(continueUrl))
            {
                continueUrl = "~/";
            }
            Response.Redirect(continueUrl);
        }
Exemplo n.º 3
0
    protected void RegisterUser_CreatedUser(object sender, EventArgs e)
    {
        FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);

        // This saves name to student table, need db finished

        //\ gets the value of the Name box
        TextBox nameText = RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("iName") as TextBox;
        String  curName  = nameText.Text;

        //\ gets value for userId
        String userId = Membership.GetUser((sender as CreateUserWizard).UserName).ProviderUserKey.ToString();

        //\ debug
        System.Diagnostics.Debug.WriteLine("name = " + curName + "  userName = "******"addUser", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@userId", userId);
                cmd.Parameters.AddWithValue("@studentName", curName);
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (SqlException)
                {
                }
            }

            con.Close();
        }



        string continueUrl = RegisterUser.ContinueDestinationPageUrl;

        if (!OpenAuth.IsLocalUrl(continueUrl))
        {
            continueUrl = "~/";
        }
        Response.Redirect(continueUrl);
    }
Exemplo n.º 4
0
        protected void newManager_CreatedUser(object sender, EventArgs e)
        {
            FormsAuthentication.SetAuthCookie(newManager.UserName, createPersistentCookie: false);

            string continueUrl = newManager.ContinueDestinationPageUrl;

            if (!OpenAuth.IsLocalUrl(continueUrl))
            {
                continueUrl = "~/";
            }

            //Roles.AddUserToRole(newManager.UserName, "Manager");

            System.Web.Security.Roles.AddUserToRole(newManager.UserName, "Manager");
        }
Exemplo n.º 5
0
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);

            WingtipToys.Logic.ShoppingCartActions usersShoppingCart = new WingtipToys.Logic.ShoppingCartActions();
            String cartId = usersShoppingCart.GetCartID();

            usersShoppingCart.MigrateCart(cartId, RegisterUser.UserName.ToString());

            string continueUrl = RegisterUser.ContinueDestinationPageUrl;

            if (!OpenAuth.IsLocalUrl(continueUrl))
            {
                continueUrl = "~/";
            }
            Response.Redirect(continueUrl);
        }
Exemplo n.º 6
0
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            var list = (RadioButtonList)this.RegisterUser.WizardSteps[0].FindControl("roles");

            System.Web.Security.Roles.AddUserToRole(
                this.RegisterUser.UserName,
                list.SelectedItem.Text);
            FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);

            string continueUrl = RegisterUser.ContinueDestinationPageUrl;

            if (!OpenAuth.IsLocalUrl(continueUrl))
            {
                continueUrl = "~/";
            }
            Response.Redirect(continueUrl);
        }
Exemplo n.º 7
0
    protected void login(object sender, EventArgs e)
    {
        string        conn = WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
        SqlConnection con  = new SqlConnection(conn);

        con.Open();

        string     query = "select * from dbo.Users where regno = @regno";
        SqlCommand cmd   = new SqlCommand(query, con);
        string     regno = ((TextBox)(Loginf.FindControl("UserName"))).Text;

        cmd.Parameters.AddWithValue("regno", regno);

        SqlDataReader rdr = cmd.ExecuteReader();

        while (rdr.Read())
        {
            string pwd  = rdr["passwd"].ToString();
            string pwd2 = ((TextBox)(Loginf.FindControl("password"))).Text;
            if (pwd.Equals(pwd2))
            {
                Session["name"]   = rdr["name"].ToString();
                Session["branch"] = rdr["branch"].ToString();
                Session["regno"]  = rdr["regno"].ToString();
                Session["cgpa"]   = rdr["cgpa"].ToString();
                string ex = "Student.aspx";
                if (rdr["regno"].ToString().Equals("admin") && rdr["post"].Equals("none"))
                {
                    ex = "Admin.aspx";
                }
                FormsAuthentication.SetAuthCookie(Session["name"].ToString(), createPersistentCookie: false);

                string continueUrl = "Default.aspx";
                if (!OpenAuth.IsLocalUrl(continueUrl))
                {
                    continueUrl = "~/Account/" + ex;
                }
                Response.Redirect(continueUrl);
            }
            else
            {
                ((Label)(Loginf.FindControl("inv"))).Text = "Wrong password.";
            }
        }
    }
Exemplo n.º 8
0
    protected void RegisterUser_CreatedUser(object sender, EventArgs e)
    {
        FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);

        //adding user to database.
        string        conn = WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
        SqlConnection con  = new SqlConnection(conn);

        con.Open();

        string name     = (RegisterUserWizardStep.ContentTemplateContainer.FindControl("UserName") as TextBox).Text,
               regno    = (RegisterUserWizardStep.ContentTemplateContainer.FindControl("regno") as TextBox).Text,
               college  = (RegisterUserWizardStep.ContentTemplateContainer.FindControl("college") as Label).Text,
               branch   = (RegisterUserWizardStep.ContentTemplateContainer.FindControl("branch") as DropDownList).SelectedItem.Text,
               password = (RegisterUserWizardStep.ContentTemplateContainer.FindControl("password") as TextBox).Text,
               cgpa     = (RegisterUserWizardStep.ContentTemplateContainer.FindControl("cgpa") as TextBox).Text;



        string     query = "insert into dbo.Users values(@name,@regno,@college,@branch,@password,@cgpa)";
        SqlCommand cmd   = new SqlCommand(query, con);

        cmd.Parameters.AddWithValue("name", name);
        cmd.Parameters.AddWithValue("regno", regno);
        cmd.Parameters.AddWithValue("college", college);
        cmd.Parameters.AddWithValue("branch", branch);
        cmd.Parameters.AddWithValue("password", password);
        cmd.Parameters.AddWithValue("cgpa", cgpa);

        cmd.ExecuteNonQuery();

        Session["name"]   = name;
        Session["branch"] = branch;
        Session["cgpa"]   = cgpa;
        Session["regno"]  = regno;
        string continueUrl = RegisterUser.ContinueDestinationPageUrl;

        if (!OpenAuth.IsLocalUrl(continueUrl))
        {
            continueUrl = "~/Account/Student.aspx";
        }
        Response.Redirect(continueUrl);
    }
Exemplo n.º 9
0
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);

            var    usuarioCarrinhoCompras = new WingTipsToys.Logic.CarrinhoActions();
            String carrinhoId             = usuarioCarrinhoCompras.GetCarrinhoId();

            usuarioCarrinhoCompras.MigrateCart(carrinhoId, RegisterUser.UserName.ToString());



            string continueUrl = RegisterUser.ContinueDestinationPageUrl;

            if (!OpenAuth.IsLocalUrl(continueUrl))
            {
                continueUrl = "~/";
            }
            Response.Redirect(continueUrl);
        }
Exemplo n.º 10
0
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            string continueUrl = RegisterUser.ContinueDestinationPageUrl;

            if (!OpenAuth.IsLocalUrl(continueUrl))
            {
                continueUrl = "~/";
            }

            var user        = UserManager.GetUser(RegisterUser.UserName);
            var profile     = new WebProfile().GetProfile(user.UserName);
            var displayName = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("DisplayName");
            var firstName   = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("FirstName");
            var lastName    = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("LastName");

            profile.DisplayName = displayName.Text;
            profile.FirstName   = firstName.Text;
            profile.LastName    = lastName.Text;

            profile.Save();

            // add users to all auto assigned roles
            var roles = RoleManager.GetAll();

            foreach (var r in roles.Where(r => r.AutoAssign))
            {
                RoleManager.AddUser(user.UserName, r.Id);
            }

            //send notification this user was created
            UserManager.SendUserRegisteredNotification(user.UserName);

            // send user verification email if enabled
            if (HostSettingManager.Get(HostSettingNames.UserRegistration, (int)UserRegistration.Verified) == (int)UserRegistration.Verified)
            {
                UserManager.SendUserVerificationNotification(user);
            }
            else
            {
                Response.Redirect(continueUrl);
            }
        }
Exemplo n.º 11
0
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);


            string response = "";
            string constr   = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

            using (SqlConnection con = new SqlConnection(constr))
            {
                using (SqlCommand cmd = new SqlCommand("dbo.piascAddUser"))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@pLogin", RegisterUser.Email);
                    cmd.Parameters.AddWithValue("@pPassword", RegisterUser.Password);

                    cmd.Connection = con;
                    con.Open();
                    response = Convert.ToString(cmd.ExecuteScalar());
                    con.Close();
                }
                if (response == "Invalid EMail")
                {
                    RegisterUser.InvalidEmailErrorMessage = "Username and/or password is incorrect.";
                }
                else
                {
                    HttpContext.Current.Session["user"] = Session.SessionID;
                    string continueUrl = RegisterUser.ContinueDestinationPageUrl;
                    if (!OpenAuth.IsLocalUrl(continueUrl))
                    {
                        continueUrl = "~/main.aspx";
                    }
                    Response.Redirect(continueUrl);
                    //Response.Redirect("~/main.aspx");
                }
            }
        }
Exemplo n.º 12
0
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);

            // SetUserRole Function
            Roles.AddUserToRole(RegisterUser.UserName, "Student");

            // saving user data in database

            var db = new CloudAppDbEntities();

            _UserEmail = RegisterUser.Email;
            _UserID    = RegisterUser.UserName;
            _UserName  = FirstName.Text + " " + MiddleName.Text + " " + LastName.Text;
            _type      = 4;
            _ClassID   = db.Class.First(c => c.ClassName == DropDownList1.SelectedValue).ClassID;

            var _User = new User()
            {
                UserID   = _UserID,
                UserName = _UserName,
                UserType = _type,
                ClassID  = _ClassID
            };

            db.User.Add(_User);
            db.SaveChanges();

            string continueUrl = RegisterUser.ContinueDestinationPageUrl;

            if (!OpenAuth.IsLocalUrl(continueUrl))
            {
                continueUrl = "~/Student/StudentHome.aspx";
            }
            Response.Redirect(continueUrl);
        }
Exemplo n.º 13
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        int                  progress             = 0;
        string               userName             = string.Empty;
        UserDetail           userDetail           = new UserDetail();
        PolinatorInformation polinatorInformation = new PolinatorInformation();
        Label                lblErrorMessage      = ((Label)LoginView1.FindControl("lblErrorMessage"));

        lblErrorMessage.Text = "";

        try
        {
            //Create new User
            //userName = ((TextBox)LoginView1.FindControl("txtUserName")).Text;
            //string password = ((TextBox)LoginView1.FindControl("txtPassword")).Text;

            string password         = string.Empty;
            string email            = ((TextBox)LoginView1.FindControl("txtEmail")).Text;
            string passwordQuestion = "Q?";
            string passwordAnswer   = "A";
            bool   isApproved       = true;
            MembershipCreateStatus status;
            string messError = string.Empty;

            //auto gen UserName, Password
            if (string.IsNullOrEmpty(userName))
            {
                userName = Utility.CreateRandomUserName(0);
            }
            if (string.IsNullOrEmpty(password))
            {
                password = Utility.CreateRandomPassword(10);
            }

            //Exec create
            System.Web.Security.Membership.CreateUser(userName, password, email, passwordQuestion, passwordAnswer, isApproved, out status);

            //status
            if (status == MembershipCreateStatus.Success)
            {
                progress = 1;
            }
            else
            {
                lblErrorMessage.Text = GetErrorMessage(status);
                return;
            }

            // Get the UserId of the just-added user
            MembershipUser newUser   = System.Web.Security.Membership.GetUser(userName);
            Guid           newUserId = (Guid)newUser.ProviderUserKey;

            //add usser to Members role
            if (!Roles.RoleExists(roleMembersName))
            {
                Roles.CreateRole(roleMembersName);
            }
            Roles.AddUserToRole(userName, roleMembersName);

            //Get Profile Data Entered by user in CUW control
            //table1: UserDetail
            userDetail.UserId          = newUserId;
            userDetail.MembershipLevel = 0;//Normal
            userDetail.FirstName       = ((TextBox)LoginView1.FindControl("txtFirstName")).Text;
            userDetail.LastName        = ((TextBox)LoginView1.FindControl("txtLastName")).Text;
            userDetail.PhoneNumber     = ((TextBox)LoginView1.FindControl("txtPhoneNumber")).Text;


            //table2: PolinatorInformation
            polinatorInformation.UserId     = newUserId;
            polinatorInformation.ExpireDate = DateTime.Now.AddDays(30);//expire after 30 days

            //Pollinator Information
            polinatorInformation.OrganizationName = ((TextBox)LoginView1.FindControl("txtOrganizationName")).Text;
            polinatorInformation.LandscapeStreet  = ((TextBox)LoginView1.FindControl("txtLandscapeStreet")).Text;
            polinatorInformation.LandscapeCity    = ((TextBox)LoginView1.FindControl("txtLandscapeCity")).Text;
            polinatorInformation.LandscapeState   = ((TextBox)LoginView1.FindControl("txtLandscapeState")).Text;
            polinatorInformation.LandscapeZipcode = ((TextBox)LoginView1.FindControl("txtLandscapeZipcode")).Text;
            //country
            polinatorInformation.LandscapeCountry = ((DropDownList)LoginView1.FindControl("ddlCountry")).SelectedValue;

            //size, type
            polinatorInformation.PollinatorSize = Int32.Parse(((DropDownList)LoginView1.FindControl("ddlPollinatorSize")).SelectedValue);
            polinatorInformation.PollinatorType = Int32.Parse(((DropDownList)LoginView1.FindControl("ddlPollinatorType")).SelectedValue);


            polinatorInformation.PhotoUrl   = ((TextBox)LoginView1.FindControl("txtPhotoUrl")).Text;
            polinatorInformation.YoutubeUrl = ((TextBox)LoginView1.FindControl("txtYoutubeUrl")).Text;

            //save lat, long
            polinatorInformation.Latitude  = decimal.Parse(hdnLat.Value);
            polinatorInformation.Longitude = decimal.Parse(hdnLng.Value);

            //update more 2 field, support PollinatorInfomation
            polinatorInformation.IsNew       = true;
            polinatorInformation.LastUpdated = DateTime.Now;

            //save to 2 tables
            mydb.UserDetails.Add(userDetail);
            mydb.PolinatorInformations.Add(polinatorInformation);
            mydb.SaveChanges();
            progress = 2;//set progress to step 2(added 2 tables)

            //set isApproved in Membership
            //newUser.IsApproved = true;
            //Membership.UpdateUser(newUser);

            //send mail default of aspnet
            SendRegisterEmailDefaultAspNet(newUser, userDetail, polinatorInformation, password);

            //Send emails asynchronously in background
            //SendRegisterEmail(userDetail, polinatorInformation);

            //Auto Approved
            AutoApproveSubmission(newUser, userDetail, polinatorInformation);
            progress = 3;//set progress to step 3(Approved)

            //Fixed bug: Auto sign in
            //if (System.Web.Security.Membership.ValidateUser(userName, password))
            //    FormsAuthentication.SetAuthCookie(userName, createPersistentCookie: false);

            //show popup
            string continueUrl = "~/Default";
            if (!OpenAuth.IsLocalUrl(continueUrl))
            {
                continueUrl = "~/";
            }

            linkReturnToMap.NavigateUrl = continueUrl;
            ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "document.getElementById('confirm_pop').click();", true);
        }
        catch (Exception ex)
        {
            //rollback
            if (progress == 1)//have just created User
            {
                System.Web.Security.Membership.DeleteUser(userName, true);
            }
            else if (progress == 2)//have created User, UserDetail, PollinatorInformation
            {
                System.Web.Security.Membership.DeleteUser(userName, true);
                if (userDetail.UserId != null)
                {
                    mydb.UserDetails.Remove(userDetail);
                    mydb.SaveChanges();
                }
                if (polinatorInformation.UserId != null)
                {
                    mydb.PolinatorInformations.Remove(polinatorInformation);
                    mydb.SaveChanges();
                }
            }

            //show error mess
            lblErrorMessage.Text = ex.Message;

            //write log
            Pollinator.Common.Logger.Error("Occured in function: " + typeof(Account_Register).Name + ".CreateUserWizard1_CreatedUser()", ex);
            //Response.Redirect("~/Default");
        }
    }