Esempio n. 1
1
		/// <summary>
		/// set http response cookies
		/// </summary>
		/// <param name="response"></param>
		/// <param name="companyUserSesson">if null-remove cookie</param>
		public void SetResponse ( HttpResponseBase response , CompanyUserSession companyUserSesson )
		{
			if (companyUserSesson != null)
			{

				if (response.Cookies[SessionIdCookieName] == null)
				{
					HttpCookie sidCookie = new HttpCookie(SessionIdCookieName, companyUserSesson.Sid);
					response.Cookies.Add(sidCookie);
				}
				else
				{
					response.Cookies[SessionIdCookieName].Value = companyUserSesson.Sid;
				}
				if (response.Cookies[UserIdCookieName] == null)
				{
					HttpCookie uIdCookie = new HttpCookie(UserIdCookieName, companyUserSesson.CompanyUserId.ToString());
					response.Cookies.Add(uIdCookie);
				}
				else
				{
					response.Cookies[UserIdCookieName].Value = companyUserSesson.CompanyUserId.ToString();
				}
			}
			else
			{
				HttpCookie uIdCookie = new HttpCookie(UserIdCookieName, "") {Expires = DateTime.Now};
				response.Cookies.Add ( uIdCookie );
				HttpCookie sidCookie = new HttpCookie(SessionIdCookieName, "") {Expires = DateTime.Now};
				response.Cookies.Add ( sidCookie );
			}
		}
Esempio n. 2
0
		public CompanyUserSession LogIn(string login, string password)
		{
			var user = _dataContext.GetCompanyUsers.FirstOrDefault(a => a.Login == login);
			if (user == null) return null;

			if (AuthUtil.ComparePasswords(user.Password, password))
			{
				var userSession = new CompanyUserSession()
				{
					Sid = Guid.NewGuid().ToString(),
					StartTime = DateTime.Now,
					CompanyUser = user
				};

				_dataContext.AddCompanyUserSession(userSession);
				_dataContext.SaveAll();
				return userSession;
			}

			return null;
		}
		public void UpdateCompanyUserSession ( CompanyUserSession companyUserSession )
		{
			var obj = CompanyUserSessions.First ( a => a.Id == companyUserSession.Id );
			obj = companyUserSession;
		}
		public void AddCompanyUserSession ( CompanyUserSession companyUserSession )
		{
			var maxCompanyUserSession = CompanyUserSessions.OrderByDescending ( a => a.Id ).FirstOrDefault ();
			companyUserSession.Id = maxCompanyUserSession != null ? maxCompanyUserSession.Id + 1 : 1;
			CompanyUserSessions.Add ( companyUserSession );
		}
		public void UpdateCompanyUserSession ( CompanyUserSession userSession ) {
			if ( userSession.Id == 0 ) {
				throw new ArgumentException ( "UpdateView id==0" );
			}
			CompanyUserSessions.Attach ( userSession );
			Entry ( userSession ).State = EntityState.Modified;
		}
		public void AddCompanyUserSession ( CompanyUserSession userSession )
		{
			CompanyUserSessions.Add ( userSession );
		}