Esempio n. 1
0
        public async Task <IActionResult> ChangePassword(PasswordsModel passwords)
        {
            //Get user id from token
            var idClaim = User.Claims.FirstOrDefault(x => x.Type.ToString().Equals("Id"));
            int id;

            if (idClaim == null)
            {
                id = 0;
            }
            else
            {
                id = int.Parse(idClaim.Value);
            }


            var user = await context.Users.FirstOrDefaultAsync(u => u.UserId == id);

            if (user == null)
            {
                return(NotFound("Incorrect Token"));
            }

            if (user.Password != passwords.OldPassword)
            {
                return(BadRequest("Incorrect old password"));
            }

            user.Password = passwords.NewPassword;
            await context.SaveChangesAsync();

            return(Ok(user));
        }
Esempio n. 2
0
        public List <PasswordsModel> GetPasswords()
        {
            List <PasswordsModel> PasswordModelList = new List <PasswordsModel>();

            try
            {
                if (File.Exists(Path.Combine((""))))
                {
                    PasswordsModel PasswordModel = new PasswordsModel();
                    PasswordModel.Company     = 1;
                    PasswordModel.Product     = 1;
                    PasswordModel.Environment = 1;
                    PasswordModel.URL         = "test";
                    PasswordModel.Password    = "******";
                    PasswordModelList.Add(PasswordModel);
                }
            }
            catch
            {
                return(null);
            }
            return(PasswordModelList);
        }