Example #1
0
        // POST: api/Login
        // In case Employee exist return UUID for using as
        // authorization haeder -
        // https://stackoverflow.com/questions/12732422/adding-header-for-httpurlconnection
        // Reading header's data
        // https://stackoverflow.com/questions/3530041/getting-a-request-headers-value

        public IHttpActionResult Post(LoginData value)
        {
            Console.WriteLine("LoginController");
            LoginPersistance loginPersistance = new LoginPersistance();

            String name = value.getName();
            String pass = value.getPassword();
            String uuid = loginPersistance.Login(name, pass);

            if ((null == uuid) || (0 == uuid.Length))
            {
                Console.WriteLine($"user {name} not found");
                Dictionary <String, object> response = new Dictionary <String, object>();
                response.Add(CsConstatnts.error, ErrorsCode.USER_NOT_FOUND);
                return(Ok(JsonUtils.toJsonStr(response)));
            }
            else
            {
                Console.WriteLine($"user {name} logged in successfully");
                Dictionary <String, object> response = new Dictionary <String, object>();
                response.Add(CsConstatnts.userName, name);
                response.Add(CsConstatnts.uuid, uuid);

                return(Ok(JsonUtils.toJsonStr(response)));
            }
        }
        // POST: api/Login
        //public void Post([FromBody]string value)
        //public LoginResponse Post([FromBody]string value)
        public LoginResponse Post(Login login)
        {
            LoginPersistance loginPersistance = new LoginPersistance();

            if (loginPersistance == null)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            //Signup signup = new Signup();

            return(loginPersistance.GetLogin(login));
        }
Example #3
0
        public IHttpActionResult Get(string name, string password)
        {
            LoginPersistance loginPersistance = new LoginPersistance();

            String usr  = name;     //  value.getName();
            String pass = password; // value.getPassword();
            String uuid = loginPersistance.Login(usr, pass);

            if ((null == uuid) && (0 == uuid.Length))
            {
                Dictionary <String, object> response = new Dictionary <String, object>();
                response.Add(CsConstatnts.error, ErrorsCode.USER_NOT_FOUND);
                return(Ok(JsonUtils.toJsonStr(response)));
            }
            else
            {
                Dictionary <String, object> response = new Dictionary <String, object>();
                response.Add(CsConstatnts.userName, name);
                response.Add(CsConstatnts.uuid, uuid);

                return(Ok(JsonUtils.toJsonStr(response)));
            }
        }