コード例 #1
0
ファイル: Default.aspx.cs プロジェクト: xdegtyarev/bsuir
        bool VerifyCredentials(string email, string password)
        {
            MongoDBConnector dbConnector = new MongoDBConnector();
            var collection  = dbConnector.GetCollection <User> ("Users");
            var q           = Query.EQ("email", email);
            var queryResult = collection.FindOne(q);

            if (queryResult != null)
            {
                return(queryResult.password == password);
            }
            return(false);
        }
コード例 #2
0
ファイル: Default.aspx.cs プロジェクト: xdegtyarev/bsuir
        ObjectId GetUserByEmail(string email)
        {
            MongoDBConnector dbConnector = new MongoDBConnector();
            var collection  = dbConnector.GetCollection <User> ("Users");
            var q           = Query.EQ("email", email);
            var queryResult = collection.FindOne(q);

            if (queryResult == null)
            {
                throw new Exception("User Not Found");
            }
            return(queryResult.Id);
        }
コード例 #3
0
ファイル: Default.aspx.cs プロジェクト: xdegtyarev/bsuir
 void Page_Load(Object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Cache.Get("currentUser") != null)
         {
             LoginStatus.Text = "Cached User Exists";
             Response.Redirect(@"~/Profile.aspx");
         }
         else
         {
             if ((Request.Browser.Cookies))
             {
                 if (Request.Cookies.Get("com.xdegtyarev.kickstart.login.email") != null &&
                     Request.Cookies.Get("com.xdegtyarev.kickstart.login.password") != null)
                 {
                     if (VerifyCredentials(Request.Cookies.Get("com.xdegtyarev.kickstart.login.email").Value, Request.Cookies.Get("com.xdegtyarev.kickstart.login.password").Value))
                     {
                         LoginStatus.Text = "Login from Cookies";
                         Cache.Insert("currentUser", GetUserByEmail(Request.Cookies.Get("com.xdegtyarev.kickstart.login.email").Value));
                         //No need to save cookies can extend cookie expiration
                         Response.Redirect("/Profile.aspx");
                     }
                     else
                     {
                         //Empty Cookies
                     }
                 }
             }
         }
         MongoDBConnector connector = new MongoDBConnector();
         var roles = connector.GetCollection <Role> ("Roles");
         if (roles.Count() > 0)
         {
             List <String> l = new List <String> ();
             foreach (var o in roles.FindAll())
             {
                 l.Add(o.type);
             }
             AcountTypeDropdownList.DataSource = l;
             AcountTypeDropdownList.DataBind();
         }
         else
         {
             RegisterButton.Visible = false;
         }
     }
 }
コード例 #4
0
ファイル: Kickstart.master.cs プロジェクト: xdegtyarev/bsuir
 void Page_Load(Object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         MongoDBConnector connector = new MongoDBConnector();
         var collection             = connector.GetCollection <User> ("Users");
         var query  = Query.EQ("id", (ObjectId)Cache.Get("currentUser"));
         var result = collection.FindOne(query);
         if (result != null)
         {
             cachedUser = result;
             ContentPlaceHolder.Page.Title = cachedUser.email;
         }
         else
         {
             //Response.Redirect("/Default.aspx");
         }
     }
 }