Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone2/sources/HeuristicLab.Security.ADODataAccess/3.2/HLUserAdapter.cs @ 6212

Last change on this file since 6212 was 1737, checked in by svonolfe, 16 years ago

Passwords are now stored in MD5 in the database (#532)

File size: 3.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.DataAccess.ADOHelper;
6using HeuristicLab.Security.Contracts.BusinessObjects;
7using HeuristicLab.Security.DataAccess;
8using HeuristicLab.Security.ADODataAccess.TableAdapterWrapper;
9
10namespace HeuristicLab.Security.ADODataAccess {
11  class HLUserAdapter: DataAdapterBase<
12      dsSecurityTableAdapters.HLUserTableAdapter,
13      User,
14      dsSecurity.HLUserRow>,
15      IUserAdapter {
16    public HLUserAdapter() :
17      base(new HLUserAdapterWrapper()) {
18    }
19
20    private IPermissionOwnerAdapter permOwnerAdapter = null;
21
22    private IPermissionOwnerAdapter PermOwnerAdapter {
23      get {
24        if (permOwnerAdapter == null)
25          permOwnerAdapter =
26            this.Session.GetDataAdapter<PermissionOwner, IPermissionOwnerAdapter>();
27
28        return permOwnerAdapter;
29      }
30    }
31
32    protected override dsSecurity.HLUserRow ConvertObj(User user, dsSecurity.HLUserRow row) {
33      if (user != null && row != null) {
34        row.PermissionOwnerId = user.Id;
35        row.Login = user.Login;
36        row.MailAddress = user.MailAddress;
37        row.Password = user.Password;
38
39        return row;
40      } else {
41        return null;
42      }
43    }
44
45    protected override User ConvertRow(dsSecurity.HLUserRow row, User user) {
46      if (user != null && row != null) {
47        /*Parent - permissionOwner*/
48        user.Id = row.PermissionOwnerId;
49        PermOwnerAdapter.GetById(user);
50
51        if (!row.IsLoginNull())
52          user.Login = row.Login;
53        else
54          user.Login = String.Empty;
55
56        if (!row.IsPasswordNull())
57          user.SetPlainPassword(row.Password);
58        else
59          user.SetPlainPassword(String.Empty);
60
61        if (!row.IsMailAddressNull())
62          user.MailAddress = row.MailAddress;
63        else
64          user.MailAddress = String.Empty;
65
66        return user;
67      } else {
68        return null;
69      }
70    }
71
72    #region IUserAdapter Members
73
74    protected override void doUpdate(User user) {
75      if (user != null) {
76        PermOwnerAdapter.Update(user);
77
78        base.doUpdate(user);
79      }
80    }
81
82    protected override bool doDelete(User user) {
83      bool success = false;
84
85      if (user != null) {
86        dsSecurity.HLUserRow row =
87          GetRowById(user.Id);
88
89        if (row != null) {
90          success = base.doDelete(user) &&
91            PermOwnerAdapter.Delete(user);
92        }
93      }
94
95      return success;
96    }
97
98    public User GetByName(string name)
99    {
100      User user = new User();
101      PermissionOwner permOwner =
102        PermOwnerAdapter.GetByName(name);
103
104      if (permOwner != null)
105        return GetById(permOwner.Id);
106      else
107        return null;
108    }
109
110    public User GetByLogin(string login) {
111      return base.FindSingle(
112        delegate() {
113          return Adapter.GetDataByLogin(login);
114        });
115    }
116
117    #endregion
118  }
119}
Note: See TracBrowser for help on using the repository browser.