protected void btnResetPassword_Click(object sender, EventArgs e)
        {
            if (Id == Guid.Empty) return;

            var newPassword = new UserManagement(Global.ConnectionString, SessionProps).ForgotPassword(UserName.Text);

            divMessage.Visible = true;

            divMessage.InnerText = "Nytt lösenord: " + newPassword;
        }
Beispiel #2
0
        public bool SignIn(string username, string password)
        {
            //try to fetch the user with the supplied username and password
            var um = new UserManagement(Global.ConnectionString, SessionProps);

            try
            {
                return um.ValidateUser(username, password);

            }
            catch(Exception exception)
            {
                lastError = exception.Message;
            }

            return false;
        }
        protected void Save_Click(object sender, EventArgs e)
        {
            //kolla först att det nuvarande lösenordet är rätt
            var um = new UserManagement(Global.ConnectionString, SessionProps);

            try
            {
                if (um.ValidateUser(SessionProps.UserName, PresentPassword.Text))
                {
                    //stämmer det nya lösenordet?
                    if (NewPassword.Text == ConfirmNewPassword.Text)
                    {
                        //uppdatera usern
                        using (var db = Global.GetConnection())
                        {
                            var userQ = from u in db.Sys_User
                                        where u.UserName == SessionProps.UserName
                                        select u;

                            var user = userQ.ToList()[0];

                            user.Password = NewPassword.Text;

                            db.SubmitChanges();

                            lblMessage.Text = "Nu är det nya lösenordet sparat";
                        }
                    }
                    else
                    {
                        lblMessage.Text = "Bekräftelsen av det nya lösenordet misslyckades";
                    }
                }
                else
                {
                    lblMessage.Text = "Det nuvarande lösenordet är felaktigt";
                }
            }
            catch (IntiGeneralException)
            {
                lblMessage.Text = "Det nuvarande lösenordet är felaktigt";
            }
        }
Beispiel #4
0
        protected void SignMeUp_Click(object sender, EventArgs e)
        {
            if (Password.Text == PasswordConfirm.Text)
            {
                try
                {

                    var um = new UserManagement(Global.ConnectionString, SessionProps);
                    um.RegisterUser(FirstName.Text, LastName.Text, Email.Text, Password.Text);

                    //if we are here, registration was successful
                    pnlForm.Visible = false;
                    lblMessage.Text = "Nu är du registrerad, gå till <a href=\"SignIn.aspx\">inloggningssidan</a> och logga in.";
                }
                catch (IntiGeneralException intiGeneralException)
                {
                    lblMessage.Text = intiGeneralException.Message;
                }
            }
            else
            {
                lblMessage.Text = "Bekräftelsen av lösenordet matchar inte lösenordet";
            }
        }
        private void LoadUser(Guid userGuid)
        {
            divMessage.Visible = false;

            var userManagement = new UserManagement(Global.ConnectionString, SessionProps);
            var user = userManagement.GetUserByGuid(userGuid);

            UserName.Text = user.UserName;
            FirstName.Text = user.FirstName;
            LastName.Text = user.LastName;

            //load permissions
            grdPermissions.DataKeyNames = new string[]{"GUID"};
            grdPermissions.DataSource = userManagement.GetPermissionsToEdit(userGuid);
            grdPermissions.DataBind();

            Id = userGuid;

            userChangeLog.LoadChangeLog(userGuid);

            pnlEditUser.Visible = true;
        }
Beispiel #6
0
        protected void login_Authenticate(object sender, AuthenticateEventArgs e)
        {
            try
            {
                e.Authenticated = SignIn(login.UserName, login.Password);

                if (e.Authenticated)
                {
                    //set login name
                    SessionProps.UserName = login.UserName;

                    //set user guid
                    var user = new UserManagement(Global.ConnectionString, SessionProps).GetUserByName(SessionProps.UserName);

                    SessionProps.UserGuid = user.GUID;

                    //set footer text
                    SessionProps.FooterText = String.Format("Inloggad som {0} {1}", user.FirstName, user.LastName);

                    //set permissions
                    SessionProps.Permissions = new UserManagement(Global.ConnectionString, SessionProps).GetUserPermissions(SessionProps.UserName);

                    //automatic signin?
                    var cookiesToAdd = new List<HttpCookie>();
                    if(login.RememberMeSet)
                    {
                        var cookie = new HttpCookie("SignMeIn", user.GUID.ToString());
                        cookie.Expires = DateTime.Now.AddYears(1);
                        cookiesToAdd.Add(cookie);
                    }

                    ////profiler on?
                    //if (SessionProps.UserGuid == new Guid("8116E67B-DBD7-40BC-932D-18DFF21B04B2"))
                    //{
                    //    var profilerCookie = new HttpCookie("Profiling", "1");
                    //    profilerCookie.Expires = DateTime.Now.AddYears(1);
                    //    cookiesToAdd.Add(profilerCookie);
                    //}

                    //add cookies?
                    if (cookiesToAdd.Count > 0)
                        Session[_cookiestoadd] = cookiesToAdd.ToArray();

                    var redirectUrl = this.GetRedirectParameter("SignInredirecturl", true);

                    if (redirectUrl == null)
                        Response.Redirect("Default.aspx");
                    else
                        Response.Redirect(redirectUrl.ToString());

                }
                else
                {
                    login.FailureText = LastError();
                }
            }
            catch (IntiGeneralException exception)
            {
                login.FailureText = exception.Message;
            }
        }
        private void GetUserHeader()
        {
            var user = new UserManagement(Global.ConnectionString, SessionProps).GetUserByGuid((Guid)ViewState["userGUID"]);

            UserName.Text = String.Format("{0} {1}", user.FirstName, user.LastName);
        }
Beispiel #8
0
        protected void Session_Start(object sender, EventArgs e)
        {
            var clientInfo = WebControlManager.GetClientInfo();
            var sessionInfo = new SessionProperties(true, clientInfo);

            //get the default tournament
            using (var db = Global.GetConnection())
            {
                var tours = from t in db.Inti_Tournament
                            select t;

                foreach (var tour in tours.OrderByDescending(tStart => tStart.StartRegistration).ToList())
                {
                    sessionInfo.SelectedTournament = tour;
                    sessionInfo.DefaultTournament = tour;
                    break;
                }

            }

            if (Request.Cookies != null)
            {
                if (Request.Cookies.Get("SignMeIn") != null)
                {
                    //automatic sign in
                    sessionInfo.UserGuid = new Guid(Request.Cookies["SignMeIn"].Value);

                    //set user guid
                    var user = new UserManagement(Global.ConnectionString, sessionInfo).GetUserByGuid(sessionInfo.UserGuid);

                    sessionInfo.UserName = user.UserName;

                    //set footer text
                    sessionInfo.FooterText = String.Format("Inloggad som {0} {1}", user.FirstName, user.LastName);

                    //set permissions
                    sessionInfo.Permissions = new UserManagement(Global.ConnectionString, sessionInfo).GetUserPermissions(sessionInfo.UserName);

                }
            }

            //set as not signed in
            HttpContext.Current.Session.RemoveAll();
            HttpContext.Current.Session.Add("sessionProps", sessionInfo);
        }