public void ProcessRequest(HttpContext context)
        {
            try
            {
                QueryParameter queryParameter = new QueryParameter(context);

                AppHttpHandler.ProcessRequest(context, queryParameter, AuthenUtil.AuthenMode.BYPASS);

                QueryResult queryResult = Login(context, queryParameter);
                context.Response.ContentType = "application/json";
                context.Response.Write(queryResult.ToJson());
                context.Response.StatusCode = (int)System.Net.HttpStatusCode.OK;

                AppHttpHandler.ProcessResponse(context);
            }
            catch (Exception exception)
            {
                AppHttpHandler.ProcessException(exception, context);
            }
            finally
            {
                context.Response.Flush();
                context.Response.End();
            }
        }
Beispiel #2
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                QueryParameter queryParameter = new QueryParameter(context);

                AppHttpHandler.ProcessRequest(context, queryParameter, AuthenUtil.AuthenMode.BYPASS);

                string mode = null;
                if (queryParameter["MODE"] != null)
                {
                    mode = queryParameter["MODE"].ToString();
                }

                QueryResult queryResult = null;
                if (mode == "CREATE")
                {
                    queryResult = CreateUser(queryParameter);
                }
                else if (mode == "UPDATE")
                {
                    queryResult = UpdateUser(queryParameter);
                }
                else if (mode == "DELETE")
                {
                    queryResult = DeleteUser(queryParameter);
                }
                else if (mode == "EXIST")
                {
                    queryResult = UserExists(queryParameter);
                }
                else if (mode == "FORGETPWD")
                {
                    queryResult = ForgetPassword(queryParameter);
                }
                else
                {
                    queryResult         = new QueryResult();
                    queryResult.Success = false;
                    queryResult.Message = "Operation Invalid";
                }

                context.Response.ContentType = "application/json";
                context.Response.Write(queryResult.ToJson());
                context.Response.StatusCode = (int)System.Net.HttpStatusCode.OK;

                AppHttpHandler.ProcessResponse(context);
            }
            catch (Exception exception)
            {
                AppHttpHandler.ProcessException(exception, context);
            }
            finally
            {
                context.Response.Flush();
                context.Response.End();
            }
        }
Beispiel #3
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                QueryParameter queryParameter = new QueryParameter(context);

                AppHttpHandler.ProcessRequest(context, queryParameter, AuthenUtil.AuthenMode.LOGIN_REQUIRED);

                Logout(context.Session, context.Response);
            }
            catch (Exception exception)
            {
                AppHttpHandler.ProcessException(exception, context);
            }
            finally
            {
                context.Response.Flush();
                context.Response.End();
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                QueryParameter queryParameter = new QueryParameter(context);

                AppHttpHandler.ProcessRequest(context, queryParameter, AuthenUtil.AuthenMode.LOGIN_REQUIRED);

                QueryResult queryResult = new QueryResult();
                int         action;
                try
                {
                    action = int.Parse(queryParameter[_appFileActionParameterName].ToString());
                }
                catch
                {
                    action = -1;
                }
                if (action == (int)Actions.Upload)
                {
                    queryResult.DataTable.Columns.Add("FILE_PARAMETER_NAME");
                    queryResult.DataTable.Columns.Add("FILE_NAME");
                    queryResult.DataTable.Columns.Add("FILE_ID");
                    foreach (string fileParameterName in context.Request.Files)
                    {
                        HttpPostedFile file         = context.Request.Files[fileParameterName];
                        string         resultFileId = null;
                        if (!string.IsNullOrEmpty(file.FileName))
                        {
                            resultFileId = SaveFile(file);
                            if (string.IsNullOrEmpty(resultFileId))
                            {
                                queryResult.Success = false;
                                queryResult.DataTable.Rows.Clear();
                                break;
                            }
                            else
                            {
                                DataRow dataRow = queryResult.DataTable.NewRow();
                                dataRow["FILE_ID"]             = resultFileId;
                                dataRow["FILE_PARAMETER_NAME"] = fileParameterName;
                                dataRow["FILE_NAME"]           = file.FileName;
                                queryResult.DataTable.Rows.Add(dataRow);
                            }
                        }
                    }
                    context.Response.ContentType = "application/json";
                    context.Response.Write(queryResult.ToJson());
                    context.Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
                }
                else if (action == (int)Actions.Download)
                {
                    string     fileId = queryParameter[_appFileFileIdParameterName].ToString();
                    string     extension;
                    FileStream f = GetFile(fileId, out extension);
                    if (f == null)
                    {
                        queryResult.Success          = false;
                        queryResult.Message          = "File not found.";
                        context.Response.ContentType = "application/json";
                        context.Response.Write(queryResult.ToJson());
                        context.Response.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
                    }
                    else
                    {
                        string fileName = "";
                        try
                        {
                            fileName = HttpUtility.UrlDecode(queryParameter[_appFileFileNameParameterName].ToString());
                        }
                        catch { }
                        if (fileName.Equals(""))
                        {
                            fileName = fileId;
                        }
                        int    length = (int)f.Length;
                        byte[] buffer = new byte[length];
                        int    sum    = 0;
                        int    count;
                        while ((count = f.Read(buffer, sum, length - sum)) > 0)
                        {
                            sum += count;
                        }
                        f.Close();
                        string contentType            = "";
                        string contentDispositionMode = "inline";
                        if (string.IsNullOrEmpty(extension))
                        {
                            contentDispositionMode = "attachment";
                        }
                        else
                        {
                            switch (extension.ToLower())
                            {
                            case ".gif":
                                contentType = "image/gif";
                                break;

                            case ".jpg":
                            case ".jpe":
                            case ".jpeg":
                                contentType = "image/jpeg";
                                break;

                            case ".png":
                                contentType = "image/png";
                                break;

                            case ".bmp":
                                contentType = "image/bmp";
                                break;

                            case ".tif":
                            case ".tiff":
                                contentType = "image/tiff";
                                break;

                            case ".eps":
                                contentType = "application/postscript";
                                break;

                            default:
                                contentDispositionMode = "attachment";
                                string mimeType = extension.ToLower();
                                mimeType    = mimeType.Replace(".", "");
                                contentType = "application/" + mimeType;
                                break;
                            }
                        }
                        context.Response.Headers.Add("Content-Length", length.ToString());
                        context.Response.Headers.Add("Content-Disposition", contentDispositionMode + "; filename=" + HttpUtility.UrlPathEncode(fileName));
                        context.Response.ContentType = contentType;
                        context.Response.BinaryWrite(buffer);
                        context.Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
                    }
                }
                else if (action == (int)Actions.Remove)
                {
                    RemoveFile(queryParameter[_appFileFileIdParameterName].ToString());
                    context.Response.ContentType = "application/json";
                    context.Response.Write(queryResult.ToJson());
                    context.Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
                }
                else
                {
                    queryResult.Success          = false;
                    queryResult.Message          = _appFileActionParameterName + " is not valid.";
                    context.Response.ContentType = "application/json";
                    context.Response.Write(queryResult.ToJson());
                    context.Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
                }

                AppHttpHandler.ProcessResponse(context);
            }
            catch (Exception exception)
            {
                AppHttpHandler.ProcessException(exception, context);
            }
            finally
            {
                context.Response.Flush();
                context.Response.End();
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                QueryParameter queryParameter = new QueryParameter(context);
                QueryResult    queryResult    = new QueryResult();

                AppHttpHandler.ProcessRequest(context, queryParameter, AuthenUtil.AuthenMode.BYPASS);

                if (context.Session != null)
                {
                    if (AppSession.GetSession("USER_ID", context.Session) != null)
                    {
                        IDatabaseConnector dbConnector = new DatabaseConnectorClass();

                        string userID  = AppSession.GetSession("USER_ID", context.Session).ToString();
                        string sqlStmt = "SELECT PASSWORD FROM UM_USER WHERE USER_ID=?";
                        queryParameter = new QueryParameter();
                        queryParameter.Add("USER_ID", userID);
                        QueryResult queryUser = dbConnector.ExecuteStatement(sqlStmt, queryParameter);
                        if (queryUser.DataTable != null && queryUser.DataTable.Rows.Count > 0)
                        {
                            queryParameter = new QueryParameter();
                            queryParameter.Add("USERNAME", userID);
                            queryParameter.Add("PASSWORD", queryUser.DataTable.Rows[0][0].ToString());
                            queryUser = dbConnector.ExecuteStoredProcedure("APP_LOGIN_Q", queryParameter);

                            queryParameter = new QueryParameter();
                            queryParameter.Add("APP_SESSION_USER_ID", userID);
                            queryResult = dbConnector.ExecuteStoredProcedure("APP_CONFIG_Q", queryParameter);

                            queryResult.AddOutputParam("userInfo", ConnectorUtil.DataTableToDictionary(queryUser.DataTable, dbConnector.DateTimeFormat, dbConnector.CultureInfo));
                        }
                    }

                    if (AppSession.GetSession("REQUEST_DATA", context.Session) != null)
                    {
                        queryResult.AddOutputParam("requestData", AppSession.GetSession("REQUEST_DATA", context.Session));
                    }
                }
                else
                {
                    throw new Exception("EMPTY_SESSION");
                }

                context.Response.ContentType = "application/json";
                context.Response.Write(queryResult.ToJson());
                context.Response.StatusCode = (int)System.Net.HttpStatusCode.OK;

                AppHttpHandler.ProcessResponse(context);
            }
            catch (Exception exception)
            {
                AppHttpHandler.ProcessException(exception, context);
            }
            finally
            {
                context.Response.Flush();
                context.Response.End();
            }
        }