예제 #1
0
        public bool LoginUserIsValid(LoginViewModel user)
        {
            if(user !=null)
            {
                var query = (from u in db.User
                             where u.Username == user.Username
                             select u).FirstOrDefault();

                if (query != null)
                {
                    if (ValidatePassword(user.Password, CreateHash(query.Password, query.Salt)))
                    {
                        userValue = query;
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            return false;
        }
예제 #2
0
        public void CreateUser(RegisterViewModel user)
        {
            OperationGroup group = db.OperationGroup.Where(m => m.Name == "Users").FirstOrDefault();
            if (user!=null)
            {
                User newUser = new User();
                newUser.Id = user.Id;
                newUser.Username = user.Username;
                newUser.Salt = CreateSalt();
                newUser.Password = user.Password;
                newUser.IsActive = true;
                newUser.data = DateTime.UtcNow.AddYears(1);

                newUser.Operations = new List<Operation>();
                newUser.OperationGroups = new List<OperationGroup>();
                newUser.OperationGroups.Add(group);
                foreach (Operation oper in group.Operations)
                {
                    if (!newUser.Operations.Contains(oper))
                    {
                        newUser.Operations.Add(oper);
                    }
                }

                db.User.Add(newUser);
                db.SaveChanges();

            }
        }
예제 #3
0
 public void EditUser(User user)
 {
     db.Entry(user).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }
예제 #4
0
        public void ChangeActivation(User user)
        {
            var obj = Find(user.Id);
            if (obj == null)
                return;
            obj.data = user.data;
            if(obj.data>DateTime.UtcNow)
            {
                obj.IsActive = true;
            }
            else
            {
                obj.IsActive = false;
            }

            db.SaveChanges();
        }