1: using System;
2: using System.Web.Http;
3:
4: namespace Ia.Ngn.Cl.Model.Api.Controller
5: {
6: ////////////////////////////////////////////////////////////////////////////
7:
8: /// <summary publish="true">
9: /// Default API Controller class.
10: /// </summary>
11: ///
12: /// <remarks>
13: /// Copyright © 2001-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
14: ///
15: /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
16: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
17: ///
18: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
19: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20: ///
21: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
22: ///
23: /// Copyright notice: This notice may not be removed or altered from any source distribution.
24: /// </remarks>
25: public class DefaultController : ApiController
26: {
27: ////////////////////////////////////////////////////////////////////////////
28:
29: /// <summary>
30: ///
31: /// </summary>
32: public DefaultController()
33: {
34: }
35:
36: ////////////////////////////////////////////////////////////////////////////
37:
38: /// <summary>
39: /// Check the validity of a password and return true if password is accepted for host.
40: /// </summary>
41: [HttpGet]
42: [Route("api/default/validate/{password}/{uriString}")]
43: public bool Validate(string password, string uriString)
44: {
45: bool isValid;
46: Uri uri;
47:
48: if (!string.IsNullOrEmpty(uriString))
49: {
50: try
51: {
52: uri = new System.Uri("http://" + uriString);
53:
54: isValid = Ia.Cl.Model.Authentication.Validate(password, uri);
55: }
56: catch (UriFormatException)
57: {
58: isValid = false;
59: }
60: }
61: else isValid = false;
62:
63: return isValid;
64: }
65:
66: ////////////////////////////////////////////////////////////////////////////
67:
68: /// <summary>
69: /// Echo the passed string
70: /// </summary>
71: [HttpGet]
72: [Route("api/default/echo/{text}")]
73: public string Echo(string text)
74: {
75: return text;
76: }
77:
78: ////////////////////////////////////////////////////////////////////////////
79:
80: /// <summary>
81: /// Return current time
82: /// </summary>
83: [HttpGet]
84: [Route("api/default/time")]
85: public string Time()
86: {
87: return DateTime.UtcNow.AddHours(3).ToString("yyyy-MM-dd HH:mm:ss.fff");
88: }
89:
90: ////////////////////////////////////////////////////////////////////////////
91: ////////////////////////////////////////////////////////////////////////////
92: }
93:
94: ////////////////////////////////////////////////////////////////////////////
95: ////////////////////////////////////////////////////////////////////////////
96: }