Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ClientUserManagement/HeuristicLab.Clients.Access/3.3/UserInformation.cs @ 7712

Last change on this file since 7712 was 7611, checked in by ascheibe, 12 years ago

#1174 added a dialog for changing the user password

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.ServiceModel.Security;
25
26namespace HeuristicLab.Clients.Access {
27  public sealed class UserInformation {
28    private static UserInformation instance;
29    public static UserInformation Instance {
30      get {
31        if (instance == null) instance = new UserInformation();
32        return instance;
33      }
34    }
35
36    private string userName;
37    public string UserName {
38      get { return userName; }
39    }
40
41    private bool userExists = false;
42    public bool UserExists {
43      get { return userExists; }
44    }
45
46    private LightweightUser user;
47    public LightweightUser User {
48      get { return user; }
49    }
50
51    //the groups a user is in
52    private List<UserGroup> groups;
53    public List<UserGroup> Groups {
54      get { return groups; }
55    }
56
57    //the roles a user has
58    private List<Role> roles;
59    public List<Role> Roles {
60      get { return roles; }
61    }
62
63    private bool errorOccured;
64    public bool ErrorOccured {
65      get { return errorOccured; }
66    }
67
68    private Exception occuredException;
69    public Exception OccuredException {
70      get { return occuredException; }
71    }
72
73    private UserInformation() {
74      //this blocks, so there should be anywhere in the Optimizer startup process
75      //a call to FetchUserInformationFromServerAsync which is non-blocking
76      FetchUserInformationFromServer();
77    }
78
79
80    private void FetchUserInformationFromServer() {
81      userName = HeuristicLab.Clients.Common.Properties.Settings.Default.UserName;
82
83      try {
84        AccessClient.CallAccessService(x => user = x.Login());
85        //TODO: get rid of the next 2 calls
86        AccessClient.CallAccessService(x => groups = x.GetGroupsOfCurrentUser());
87        AccessClient.CallAccessService(x => roles = x.GetRolesOfCurrentUser());
88        errorOccured = false;
89        userExists = true;
90        occuredException = null;
91      }
92      catch (MessageSecurityException e) {
93        //wrong username or password
94        errorOccured = false;
95        userExists = false;
96        occuredException = e;
97      }
98      catch (Exception e) {
99        errorOccured = true;
100        userExists = false;
101        occuredException = e;
102      }
103    }
104
105    public void Refresh() {
106      FetchUserInformationFromServer();
107    }
108  }
109}
Note: See TracBrowser for help on using the repository browser.