From: <mar...@us...> - 2010-02-13 20:47:47
|
Revision: 23 http://cronoscontrol.svn.sourceforge.net/cronoscontrol/?rev=23&view=rev Author: marioarce Date: 2010-02-13 20:47:40 +0000 (Sat, 13 Feb 2010) Log Message: ----------- Ticket #7 Implementing user authentication and session Classes /CronosControlContext.cs * represents a CronosControl Context , added some base methods to manage current session, current context objects, values and properties, and to manage cookies and culture Classes /Tracker/TrackerSession.cs * represents a tracker session object Added Paths: ----------- source/trunk/CronosControl/Libraries/BusinessLogic/BaseEntity.cs source/trunk/CronosControl/Libraries/BusinessLogic/CronosControlContext.cs source/trunk/CronosControl/Libraries/BusinessLogic/Tracker/TrackerSession.cs Added: source/trunk/CronosControl/Libraries/BusinessLogic/BaseEntity.cs =================================================================== --- source/trunk/CronosControl/Libraries/BusinessLogic/BaseEntity.cs (rev 0) +++ source/trunk/CronosControl/Libraries/BusinessLogic/BaseEntity.cs 2010-02-13 20:47:40 UTC (rev 23) @@ -0,0 +1,28 @@ +//------------------------------------------------------------------------------ +// The contents of this file are subject to the GNU General Public License Version 3.0 ("License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at http://www.cronoscontrol.net/license.html. +// +// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. +// See the License for the specific language governing rights and limitations under the License. +// +// The Original Code is CronosControl. +// The Initial Developer of the Original Code is WebImageConsulting http://www.wicnow.com/. +// All Rights Reserved. +// +// Contributor(s): Mario Alberto Arce, _______. +//------------------------------------------------------------------------------ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace CronosControl.BusinessLogic +{ + /// <summary> + /// Provides a base class for entities + /// </summary> + public abstract partial class BaseEntity + { + } +} Added: source/trunk/CronosControl/Libraries/BusinessLogic/CronosControlContext.cs =================================================================== --- source/trunk/CronosControl/Libraries/BusinessLogic/CronosControlContext.cs (rev 0) +++ source/trunk/CronosControl/Libraries/BusinessLogic/CronosControlContext.cs 2010-02-13 20:47:40 UTC (rev 23) @@ -0,0 +1,266 @@ +//------------------------------------------------------------------------------ +// The contents of this file are subject to the GNU General Public License Version 3.0 ("License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at http://www.cronoscontrol.net/license.html. +// +// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. +// See the License for the specific language governing rights and limitations under the License. +// +// The Original Code is CronosControl. +// The Initial Developer of the Original Code is WebImageConsulting http://www.wicnow.com/. +// All Rights Reserved. +// +// Contributor(s): Mario Alberto Arce, _______. +//------------------------------------------------------------------------------ + +using System; +using System.Globalization; +using System.Threading; +using System.Web; +using CronosControl.Model; +using CronosControl.BusinessLogic.Tracker; +using CronosControl.BusinessLogic.Configuration.Settings; + +namespace CronosControl.BusinessLogic +{ + /// <summary> + /// Represents a CronosControlContext + /// </summary> + public partial class CronosControlContext + { + #region Constants + private const string CONST_TRACKERSESSION = "CronosControl.TrackerSession"; + private const string CONST_TRACKERSESSIONCOOKIE = "CronosControl.TrackerSessionGUIDCookie"; + #endregion + + #region Fields + private User currentTracker; + private bool isAdmin; + private HttpContext context = HttpContext.Current; + private Project currentProject; + private Company currentCompany; + #endregion + + #region Constructor + /// <summary> + /// Creates a new instance of the CronosControlContext class + /// </summary> + private CronosControlContext() + { + + } + #endregion + + #region Methods + /// <summary> + /// Save tracker session to data source + /// </summary> + /// <returns>Saved tracker session</returns> + private TrackerSession SaveSessionToDatabase() + { + return null; + } + + /// <summary> + /// Gets tracker session + /// </summary> + /// <param name="createInDatabase">Create session in database if no one exists</param> + /// <returns>Tracker session</returns> + public TrackerSession GetSession(bool createInDatabase) + { + return this.GetSession(createInDatabase, null); + } + + /// <summary> + /// Gets tracker session + /// </summary> + /// <param name="createInDatabase">Create session in database if no one exists</param> + /// <param name="sessionId">Session identifier</param> + /// <returns>Tracker session</returns> + public TrackerSession GetSession(bool createInDatabase, Guid? sessionId) + { + return null; + } + + /// <summary> + /// Saves current session to client + /// </summary> + public void SessionSaveToClient() + { + if (HttpContext.Current != null && this.Session != null) + SetCookie(HttpContext.Current.ApplicationInstance, CONST_TRACKERSESSIONCOOKIE, this.Session.TrackerSessionGUID.ToString()); + } + + /// <summary> + /// Reset tracker session + /// </summary> + public void ResetSession() + { + if (HttpContext.Current != null) + SetCookie(HttpContext.Current.ApplicationInstance, CONST_TRACKERSESSIONCOOKIE, string.Empty); + this.Session = null; + this.User = null; + this["CronosControl.SessionReseted"] = true; + } + + /// <summary> + /// Sets cookie + /// </summary> + /// <param name="application">Application</param> + /// <param name="key">Key</param> + /// <param name="val">Value</param> + private static void SetCookie(HttpApplication application, string key, string val) + { + HttpCookie cookie = new HttpCookie(key); + cookie.Value = val; + if (string.IsNullOrEmpty(val)) + { + cookie.Expires = DateTime.Now.AddMonths(-1); + } + else + { + cookie.Expires = DateTime.Now.AddHours(Convert.ToDouble(SettingManager.Current["base", "cookieExpires"])); + } + application.Response.Cookies.Remove(key); + application.Response.Cookies.Add(cookie); + } + #endregion + + #region Properties + /// <summary> + /// Gets an instance of the CronosControlContext, which can be used to retrieve information about current context. + /// </summary> + public static CronosControlContext Current + { + get + { + if (HttpContext.Current == null) + return null; + + if (HttpContext.Current.Items["CronosControlContext"] == null) + { + CronosControlContext context2 = new CronosControlContext(); + HttpContext.Current.Items.Add("CronosControlContext", context2); + return context2; + } + return (CronosControlContext)HttpContext.Current.Items["CronosControlContext"]; + } + } + + /// <summary> + /// Gets or sets a value indicating whether the context is running in admin-mode + /// </summary> + public bool IsAdmin + { + get + { + return isAdmin; + } + set + { + isAdmin = value; + } + } + + /// <summary> + /// Gets or sets an object item in the context by the specified key. + /// </summary> + /// <param name="key">The key of the value to get.</param> + /// <returns>The value associated with the specified key.</returns> + public object this[string key] + { + get + { + if (this.context == null) + { + return null; + } + + if (this.context.Items[key] != null) + { + return this.context.Items[key]; + } + return null; + } + set + { + if (this.context != null) + { + this.context.Items.Remove(key); + this.context.Items.Add(key, value); + + } + } + } + + /// <summary> + /// Gets or sets the current session + /// </summary> + public TrackerSession Session + { + get + { + return this.GetSession(false); + } + set + { + Current[CONST_TRACKERSESSION] = value; + } + } + + /// <summary> + /// Gets or sets the current user + /// </summary> + public User User + { + get + { + return this.currentTracker; + } + set + { + this.currentTracker = value; + } + } + + /// <summary> + /// Gets or sets the current project + /// </summary> + public Project CurrentProject + { + get + { + return this.currentProject; + } + set + { + this.currentProject = value; + } + } + + /// <summary> + /// Gets or sets the current company + /// </summary> + public Company CurrentCompany + { + get + { + return this.currentCompany; + } + set + { + this.currentCompany = value; + } + } + + /// <summary> + /// Sets the CultureInfo + /// </summary> + /// <param name="culture">Culture</param> + public void SetCulture(CultureInfo culture) + { + Thread.CurrentThread.CurrentCulture = culture; + Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; + } + #endregion + } +} Added: source/trunk/CronosControl/Libraries/BusinessLogic/Tracker/TrackerSession.cs =================================================================== --- source/trunk/CronosControl/Libraries/BusinessLogic/Tracker/TrackerSession.cs (rev 0) +++ source/trunk/CronosControl/Libraries/BusinessLogic/Tracker/TrackerSession.cs 2010-02-13 20:47:40 UTC (rev 23) @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// The contents of this file are subject to the GNU General Public License Version 3.0 ("License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at http://www.cronoscontrol.net/license.html. +// +// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. +// See the License for the specific language governing rights and limitations under the License. +// +// The Original Code is CronosControl. +// The Initial Developer of the Original Code is WebImageConsulting http://www.wicnow.com/. +// All Rights Reserved. +// +// Contributor(s): Mario Alberto Arce, _______. +//------------------------------------------------------------------------------ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Text; +using System.Web; +using System.Xml; +using CronosControl.Model; + +namespace CronosControl.BusinessLogic.Tracker +{ + /// <summary> + /// Represents a tracker session + /// </summary> + public partial class TrackerSession : BaseEntity + { + #region Constructor + /// <summary> + /// Creates a new instance of the TrackerSession class + /// </summary> + public TrackerSession() + { + } + #endregion + + #region Properties + /// <summary> + /// Gets or sets the tracker session identifier + /// </summary> + public Guid TrackerSessionGUID { get; set; } + + /// <summary> + /// Gets or sets the tracker identifier + /// </summary> + public int TrackerID { get; set; } + + /// <summary> + /// Gets or sets the last accessed date and time + /// </summary> + public DateTime LastAccessed { get; set; } + + /// <summary> + /// Gets or sets a value indicating whether the tracker session is expired + /// </summary> + public bool IsExpired { get; set; } + #endregion + + #region Custom Properties + /// <summary> + /// Gets or sets the tracker + /// </summary> + public User User + { + get + { + return TrackerManager.GetTrackerByID(TrackerID); + } + } + #endregion + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |