예제 #1
0
        public UserAuthenticationModel Authenticate(string userName, string passWord)
        {
            var model = new UserAuthenticationModel();
            var encryptedPassword = HashPassword(passWord);
            using (var ctx = new FightFleetDataContext())
            {
                var user = ctx.Users.FirstOrDefault(c => c.UserName.ToLower() == userName.ToLower()
                    && c.Password == encryptedPassword);
                if (user == null)
                    return model;

                model.UserName = user.UserName;
                model.UserId = user.UserId;
                var authentication = user.Authentications.FirstOrDefault(c => c.ExpiresOn >= DateTime.Now);
                if (authentication == null )
                {
                    authentication = new Authentication
                    {
                        ExpiresOn = DateTime.Now.AddDays(7),
                        AccessToken = Guid.NewGuid(),
                        CreatedOn = DateTime.Now,

                    };
                    user.Authentications.Add(authentication);
                    ctx.SubmitChanges();
                }
                else if ((DateTime.Now - authentication.ExpiresOn).TotalDays <= 1)
                {
                    authentication.ExpiresOn = DateTime.Now.AddDays(7);
                    ctx.SubmitChanges();
                }
                model.AccessToken = authentication.AccessToken;
            }

            return model;
        }
예제 #2
0
 partial void DeleteAuthentication(Authentication instance);
예제 #3
0
 partial void InsertAuthentication(Authentication instance);
예제 #4
0
 partial void UpdateAuthentication(Authentication instance);
예제 #5
0
		private void detach_Authentications(Authentication entity)
		{
			this.SendPropertyChanging();
			entity.User = null;
		}