소스 검색

Load password profile if site matching

fix https://github.com/lesspass/lesspass/issues/95
pull/342/head
Guillaume Vincent 7 년 전
부모
커밋
20edf94d92
8개의 변경된 파일76개의 추가작업 그리고 8개의 파일을 삭제
  1. +5
    -1
      src/domain/url-parser.js
  2. +4
    -0
      src/store/actions.js
  3. +2
    -1
      src/store/mutation-types.js
  4. +14
    -0
      src/store/mutations.js
  5. +0
    -1
      src/views/ConfigureOptions.vue
  6. +1
    -2
      src/views/PasswordGenerator.vue
  7. +47
    -1
      test/store.mutations.js
  8. +3
    -2
      test/url-parser.js

+ 5
- 1
src/domain/url-parser.js 파일 보기

@@ -18,7 +18,11 @@ export function getSite() {
return new Promise(resolve => {
if (typeof chrome !== 'undefined' && typeof chrome.tabs !== 'undefined' && typeof chrome.tabs.query !== 'undefined') {
chrome.tabs.query({active: true, currentWindow: true}, tabs => {
resolve(getDomainName(tabs[0].url));
const url = tabs[0].url;
resolve({
site: getDomainName(url),
url: url
});
});
} else {
resolve('');


+ 4
- 0
src/store/actions.js 파일 보기

@@ -12,6 +12,10 @@ export const loadPasswordFirstTime = ({commit}) => {
commit(types.LOAD_PASSWORD_FIRST_TIME);
};

export const loadPasswordForSite = ({commit}, payload) => {
commit(types.LOAD_PASSWORD_FOR_SITE, payload);
};

export const saveDefaultPassword = ({commit}, payload) => {
commit(types.SET_DEFAULT_PASSWORD, payload);
};


+ 2
- 1
src/store/mutation-types.js 파일 보기

@@ -6,4 +6,5 @@ export const SET_PASSWORDS = 'SET_PASSWORDS';
export const DELETE_PASSWORD = 'DELETE_PASSWORD';
export const SET_BASE_URL = 'SET_BASE_URL';
export const SET_VERSION = 'SET_VERSION';
export const LOAD_PASSWORD_FIRST_TIME = 'LOAD_PASSWORD_FIRST_TIME';
export const LOAD_PASSWORD_FIRST_TIME = 'LOAD_PASSWORD_FIRST_TIME';
export const LOAD_PASSWORD_FOR_SITE = 'LOAD_PASSWORD_FOR_SITE';

+ 14
- 0
src/store/mutations.js 파일 보기

@@ -45,5 +45,19 @@ export default {
if (tenMinutesAgo > state.lastUse) {
setState(state, 'password', state.defaultPassword);
}
},
[types.LOAD_PASSWORD_FOR_SITE](state, {site, url}){
state.password.site = site;
const passwords = state.passwords;
for (let i = 0; i < state.passwords.length; i++) {
const password = passwords[i];
if (password.site.endsWith(site)) {
setState(state, 'password', password);
}
if (typeof url !== 'undefined' && url.includes(password.site)) {
setState(state, 'password', password);
break;
}
}
}
};

+ 0
- 1
src/views/ConfigureOptions.vue 파일 보기

@@ -43,7 +43,6 @@
}, 3000);
},
updatePassword(password){
console.log(password);
this.options = password;
}
}


+ 1
- 2
src/views/PasswordGenerator.vue 파일 보기

@@ -180,8 +180,7 @@

getSite().then(site => {
if (site) {
this.password.site = site;
this.$store.dispatch('savePassword', {password: this.password});
this.$store.dispatch('loadPasswordForSite', site);
}
});



+ 47
- 1
test/store.mutations.js 파일 보기

@@ -186,6 +186,52 @@ test('LOAD_PASSWORD_FIRST_TIME last use null', t => {
};
const LOAD_PASSWORD_FIRST_TIME = mutations[types.LOAD_PASSWORD_FIRST_TIME];
LOAD_PASSWORD_FIRST_TIME(state);
t.is(state.password.version,2);
t.is(state.password.version, 2);
timekeeper.reset();
});

test('LOAD_PASSWORD_FOR_SITE', t => {
const state = {
password: {
site: ''
},
passwords: [
{id: '1', site: 'www.example.org'},
{id: '2', site: 'www.google.com'}
]
};
const LOAD_PASSWORD_FOR_SITE = mutations[types.LOAD_PASSWORD_FOR_SITE];
LOAD_PASSWORD_FOR_SITE(state, {site: 'google.com'});
t.is(state.password.id, '2');
t.is(state.password.site, 'www.google.com');
});

test('LOAD_PASSWORD_FOR_SITE no passwords', t => {
const state = {
password: {
site: ''
},
passwords: []
};
const LOAD_PASSWORD_FOR_SITE = mutations[types.LOAD_PASSWORD_FOR_SITE];
LOAD_PASSWORD_FOR_SITE(state, {site: 'google.com'});
t.false('id' in state.password);
t.is(state.password.site, 'google.com');
});

test('LOAD_PASSWORD_FOR_SITE multiple accounts matching criteria', t => {
const state = {
password: {
site: ''
},
passwords: [
{id: '1', site: 'www.example.org'},
{id: '2', site: 'www.google.com'},
{id: '3', site: 'account.google.com'},
]
};
const LOAD_PASSWORD_FOR_SITE = mutations[types.LOAD_PASSWORD_FOR_SITE];
LOAD_PASSWORD_FOR_SITE(state, {site: 'google.com', url: 'https://www.google.com'});
t.is(state.password.id, '2');
t.is(state.password.site, 'www.google.com');
});

+ 3
- 2
test/url-parser.js 파일 보기

@@ -26,8 +26,9 @@ test('get current tab', t => {
}
}
};
return urlParser.getSite().then(site => {
t.is(site, 'example.org')
return urlParser.getSite().then(response => {
t.is(response.url, url);
t.is(response.site, 'example.org')
});
});



불러오는 중...
취소
저장