using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Spaces;
using Spaces.Controls;

public partial class Manage_GoToUserAdmin : ManagePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
        string username = Request.QueryString["username"];
        string password = Request.QueryString["Password"];
        //password = Utils.PasswordFormat(password);
        Spaces.User user = Users.GetUser(username.ToLower());
        if (user == null)
        {
            string script = "<script>alert('用户名不存在！');history.go(-1);</script>";
            this.RegisterStartupScript("accountErr", script);
            return;
        }
        if (user.Password != password)
        {
            string script = "<script>alert('密码错误！');history.go(-1);</script>";
            this.RegisterStartupScript("passwordErr", script);
            return;

        }
        

        SetTicket(username, true);
        Response.Redirect(string.Format("{0}/Admin",Globals.ApplicationPath));
    }
    public void SetTicket(string name, bool isPersistent)
    {
        FormsAuthentication.SetAuthCookie(name, isPersistent);

        //  this.Literal1.Text = GetCurrentUserName + "" + Page.User.Identity.Name;
        string userData = "username|userid|userdepart";

        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
        1,
        name,
        System.DateTime.Now,
        System.DateTime.Now.AddDays(7),
        isPersistent,
        userData,
        FormsAuthentication.FormsCookiePath);

        // Encrypt the ticket. 
        string encTicket = FormsAuthentication.Encrypt(ticket);

        // Create the cookie. 
        Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));

        // FormsAuthentication.RedirectFromLoginPage(name, isPersistent);
    }
}
