summaryrefslogtreecommitdiff
path: root/demos/time-tracker/protected/App_Data/mysql-maps/users.xml
blob: 6053c7ea25ba4d655d7c0f42f1ecf98671280028 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?xml version="1.0" encoding="utf-8" ?>
<sqlMap>

<resultMap id="time-tracker-user" class="TimeTrackerUser" GroupBy="Name">
	<result property="Name" column="Name" />
	<result property="EmailAddress" column="EmailAddress" />
	<result property="Roles" Type="array" resultMapping="user-roles-result" />
</resultMap>

<resultMap id="user-roles-result">
	<result column="role" />
</resultMap>

<!--
<select id="GetUserByName" parameterClass="string" resultMap="TimeTrackerUser">
	SELECT 
		users.Username as Name,
		users.EmailAddress as EmailAddress,
		user_roles.RoleType as role
	FROM
		users
		LEFT JOIN user_roles ON users.Username = user_roles.UserID
	WHERE
		Username = #value#
	AND 
		Disabled = 0
</select>
-->

<select id="UsernameExists" parameterClass="string" resultClass="boolean">
	SELECT COUNT(Username) FROM users WHERE Username = #value#
</select>

<select id="GetUserByName" parameterClass="string" resultMap="time-tracker-user">
	SELECT 
		users.Username as Name,
		users.EmailAddress as EmailAddress,
		user_roles.RoleType as role
	FROM
		users
		LEFT JOIN user_roles ON users.Username = user_roles.UserID
	WHERE
		Username = #value#
	AND 
		Disabled = 0
</select>
    
<select id="GetAllUsers" resultMap="time-tracker-user">
	SELECT
		users.Username as Name,
		users.EmailAddress as EmailAddress,
		user_roles.RoleType as role
	FROM
		users
		LEFT JOIN user_roles ON users.Username = user_roles.UserID
	WHERE
		Disabled = 0
</select>

<select id="ValidateUser" resultClass="boolean">
	SELECT 
		count(Username)
	FROM
		users
	WHERE
		username = #username# AND password = #password#
	AND
		Disabled = 0
</select>

<insert id="AddNewUser" parameterClass="array">
	INSERT INTO 
		users (Username, Password, EmailAddress)
	VALUES
		(#user.Name#, #password#, #user.EmailAddress#)
</insert>

<update id="DeleteUserByName">
	UPDATE users SET Disabled = 1  WHERE username = #value#
</update>

<insert id="RegisterAutoSignon" parameterClass="array">
	INSERT INTO 
		signon (SessionToken, Username, LastSignOnDate)
	VALUES
		(#token#, #username#, NOW())
</insert>

<select id="ValidateAutoSignon" resultMap="time-tracker-user">
	SELECT
		users.Username as Name,
		users.EmailAddress as EmailAddress,
		user_roles.RoleType as role
	FROM
		users LEFT JOIN user_roles ON users.Username = user_roles.UserID,
		signon
	WHERE
		users.Username = signon.Username
		AND signon.SessionToken = #value#
		AND users.Disabled = 0
</select>

<update id="UpdateSignon">
	UPDATE signon SET LastSignOnDate = NOW() 
	WHERE SessionToken = #value#
</update>

<delete id="DeleteUserRoles" parameterClass="TimeTrackerUser">
	DELETE FROM user_roles WHERE UserID = #Name#
</delete>

<update id="AddUserRole" parameterClass="array">
	INSERT INTO user_roles (UserID, RoleType)
	VALUES(#username#, #role#)
</update>

<update id="UpdateUserDetails" parameterClass="TimeTrackerUser">
	UPDATE users 
	SET EmailAddress = #EmailAddress#
	WHERE Username = #Name#
</update>

<update id="UpdateUserDetailsAndPassword" parameterClass="array">
	UPDATE users 
	SET EmailAddress = #user.EmailAddress#, Password=#password#
	WHERE Username = #user.Name#
</update>

<delete id="DeleteAutoSignon">
	DELETE FROM signon WHERE Username = #value#
</delete>

<delete id="DeleteAllSignon">
	DELETE FROM signon
</delete>

</sqlMap>