Ejemplo n.º 1
0
        public DBUser Create()
        {
            if (!Exists())
            {
                //set auth type and hash pwd
                if (User == null)
                {
                    User = new DBUser();
                    User.username = _identity.Name;
                }
               

                User.authtype = "Form";
                if(_identity.AuthenticationType.Length>0){
                    User.authtype = _identity.AuthenticationType;
                    
                }
                if (User.authtype == "Form") {
                    User.password = HashingService.MakeHash(User.password);
                }

                ctx.DBUsers.Add(User);
                ctx.Context.SaveChanges();
                User.password = string.Empty;
                return User;

            }
            else
            {
                return User;
            }

        }
Ejemplo n.º 2
0
 public VMUser(DBUser user)
 {
     username = user.username;
     email = user.email;
     firstname = user.firstname;
     lastname = user.lastname;
     authenticated = true;
     authtype = user.authtype;
 }
Ejemplo n.º 3
0
 public User(DBUser user)
 {
     ID = user.ID;
     username = user.username;
     email = user.email;
     firstname = user.firstname;
     lastname = user.lastname;
     //picture = user.picture;
     authenticated = true;
     auth = user.authtype;
 }
Ejemplo n.º 4
0
        public void Update(DBUser user)
        {

            DBUser target = ctx.DBUsers.Where(x => x.ID == user.ID).FirstOrDefault<DBUser>(); ;



            target.username = user.username;
            target.lastname = user.lastname;
            target.firstname = user.firstname;
            target.email = user.email;
            target.picture = user.picture;
            if (user.password.Length > 0)
            {
                target.password = user.password;
            }

            ctx.Context.Entry<DBUser>(target).State = EntityState.Modified;
            ctx.Context.SaveChanges();
            
        }
Ejemplo n.º 5
0
        public void Update(DBUser user)
        {
            DBUser target = _ctx.DBUsers.Find(user.ID);

            target.username = user.username;
            target.lastname = user.lastname;
            target.firstname = user.firstname;
            target.email = user.email;
            target.picture = user.picture;
            if (user.authtype == "Form")
            {

                var hashedpassword = HashingService.MakeHash(user.password);

                if (user.password.Length > 0 && target.password != hashedpassword && user.password != "blankpassword" && user.password != target.password)
                {
                    target.password = hashedpassword;
                }
            }
            _ctx.Entry<DBUser>(target).State = System.Data.Entity.EntityState.Modified;
            _ctx.SaveChanges();
        }
Ejemplo n.º 6
0
 public DBUser RefreshUser()
 {
     _User = null;
     return User;
 }
Ejemplo n.º 7
0
        public DBUser IsValidUser(string username, string password)
        {
            CTX ctx = new CTX();
            DBUser user;

            Boolean useForms = true;
            Boolean.TryParse(ConfigurationManager.AppSettings["Forms"], out useForms);

            if (!useForms)
            {
                //if the user name is blank... check for the user from windows auth and pass it.
                var identity = System.Security.Principal.WindowsIdentity.GetCurrent();
                username = identity.Name;
                user = ctx.DBUsers.Where(x => x.username == username).FirstOrDefault<DBUser>();
                if (user == null)
                {
                    //user auth via windows auth but not in database so add him to db and auth

                    var _User = new DBUser();
                    _User.authtype = identity.AuthenticationType;
                    _User.username = username;
                    ctx.DBUsers.Add(_User);
                    ctx.SaveChanges();
                    User = _User;
                    return _User;

                }
                else
                {

                    User = user;
                    return user;

                }

            }
            else
            {

                if (username == string.Empty || username == null)
                {
                    return null;

                }

                user = ctx.DBUsers.Where(x => x.username == username).FirstOrDefault<DBUser>();

                if (user == null)
                {
                    return null;
                }

                if (HashingService.ValidateHash(user.password, password))
                {

                    User = user;
                    return user;
                }
                else
                {
                    return null;
                }

            }
        }