PageRenderTime 27ms CodeModel.GetById 19ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/Account/login.aspx.cs

#
C# | 70 lines | 50 code | 11 blank | 9 comment | 12 complexity | 2b21926ff9e820cd98d0cc65cb0c2561 MD5 | raw file
 1namespace Account
 2{
 3    using System;
 4    using System.Web;
 5    using System.Web.Security;
 6    using System.Web.UI;
 7    using System.Web.UI.WebControls;
 8    using BlogEngine.Core;
 9
10    using Resources;
11
12    /// <summary>
13    /// The login.
14    /// </summary>
15    public partial class Login : System.Web.UI.Page
16    {
17        #region Methods
18
19        /// <summary>
20        /// Handles the Load event of the Page control.
21        /// </summary>
22        /// <param name="sender">The source of the event.</param>
23        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
24        protected void Page_Load(object sender, EventArgs e)
25        {
26            HyperLink linkForgotPassword = (HyperLink)LoginUser.FindControl("linkForgotPassword");
27            if (linkForgotPassword != null)
28            {
29                linkForgotPassword.NavigateUrl = Utils.RelativeWebRoot + "Account/password-retrieval.aspx";
30            }
31
32            this.RegisterHyperLink.NavigateUrl = Utils.RelativeWebRoot + "Account/register.aspx?ReturnUrl=" +
33                                                 HttpUtility.UrlEncode(this.Request.QueryString["ReturnUrl"]);
34            this.RegisterHyperLink.Text = labels.createNow;
35            ((PlaceHolder)LoginUser.FindControl("phResetPassword")).Visible = BlogSettings.Instance.EnablePasswordReset;
36
37            if (this.Request.QueryString.ToString() == "logoff")
38            {
39                Security.SignOut();
40                if (this.Request.UrlReferrer != null && this.Request.UrlReferrer != this.Request.Url && this.Request.UrlReferrer.LocalPath.IndexOf("/admin/", StringComparison.OrdinalIgnoreCase) == -1)
41                {
42                    this.Response.Redirect(this.Request.UrlReferrer.ToString(), true);
43                }
44                else
45                {
46                    this.Response.Redirect(BlogEngine.Core.Utils.RelativeWebRoot);
47                }
48
49                return;
50            }
51
52            if (!this.Page.IsPostBack || Security.IsAuthenticated)
53            {
54                return;
55            }
56
57            this.Master.SetStatus("warning", Resources.labels.loginFailed);
58        }
59
60        protected void LoginUser_OnAuthenticate(object sender, AuthenticateEventArgs e)
61        {
62            // always set to false
63            e.Authenticated = false;
64
65            Security.AuthenticateUser(LoginUser.UserName, LoginUser.Password, LoginUser.RememberMeSet);
66        }
67
68        #endregion
69    }
70}