コード例 #1
0
ファイル: UserManager.cs プロジェクト: Nageena/Fight-Fleet
        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;
		}