Exemplo n.º 1
0
        public JsonResult OnPost()
        {
            login_db           _context = new login_db(AppGlobal.get_db_option()); //simplifying context initializer by override
            AppResponseMessage arm      = new AppResponseMessage();                //inisialisasi ARM sebagai standarisasi respon balik

            try {
                using (var transaction = _context.Database.BeginTransaction()) {
                    if (Request.Query["f"] == "logout_handler")
                    {
                        var history_id = User.FindFirst("history_id").Value;

                        var history = _context.t_login_history.FirstOrDefault(e => e.t_login_history_id == Convert.ToInt32(history_id));

                        history.logout_time = DateTime.Now;
                        _context.t_login_history.Update(history);
                        _context.SaveChanges();

                        AuthenticationHttpContextExtensions.SignOutAsync(HttpContext, CookieAuthenticationDefaults.AuthenticationScheme);

                        arm.success();
                        arm.message = "Success";
                    }
                    transaction.Commit();
                    _context.SaveChanges();
                }
            } catch (Exception ex) {
                arm.fail();
                arm.message = ex.Message;
            }
            return(new JsonResult(arm)); //return ARM dg method JsonResult untuk auto serialize ke format JSON
        }
Exemplo n.º 2
0
        public JsonResult OnPost(int n_number)
        {
            AppResponseMessage arm = new AppResponseMessage();

            arm.success();
            arm.message = "Success";
            arm.data    = count(n_number);
            return(new JsonResult(arm));
        }
Exemplo n.º 3
0
        public JsonResult OnPost()
        {
            login_db           _context = new login_db(AppGlobal.get_db_option()); //simplifying context initializer by override
            AppResponseMessage arm      = new AppResponseMessage();                //inisialisasi ARM sebagai standarisasi respon balik

            try {
                using (var transaction = _context.Database.BeginTransaction()) {
                    if (Request.Query["f"] == "login_handler")
                    {
                        string email    = Request.Form["email"];
                        string password = Request.Form["password"];
                        var    m_user   = _context.m_user.FirstOrDefault(e => e.email == email && e.password == password);
                        if (m_user == null)
                        {
                            arm.fail();
                            arm.message = "Data Not Exist!!";
                        }
                        else
                        {
                            t_login_history login_history = new t_login_history {
                                m_user_id  = m_user.m_user_id,
                                login_time = DateTime.Now
                            };

                            _context.t_login_history.Add(login_history);
                            _context.SaveChanges();

                            //jika user valid & aktif
                            var claims = new[] {
                                new Claim(ClaimTypes.Email, email),

                                new Claim("m_user_id", m_user.m_user_id.ToString()),
                                new Claim("full_name", m_user.full_name),
                                new Claim("history_id", login_history.t_login_history_id.ToString()),
                            };
                            ClaimsIdentity  identity  = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                            ClaimsPrincipal principal = new ClaimsPrincipal(identity);

                            AuthenticationHttpContextExtensions.SignInAsync(HttpContext, CookieAuthenticationDefaults.AuthenticationScheme, principal);

                            arm.success();
                            arm.message = "Success";
                        }
                    }
                    transaction.Commit();
                    _context.SaveChanges();
                }
            } catch (Exception ex) {
                arm.fail();
                arm.message = ex.Message;
            }
            return(new JsonResult(arm)); //return ARM dg method JsonResult untuk auto serialize ke format JSON
        }
Exemplo n.º 4
0
        public static HttpResponseMessageWrapperEx ToTransportResponse(this AppResponseMessage response)
        {
            // Could interact with the wrapper directly, but trying to use
            // http message as much as possible so that if we want to push
            // the wrapper contents into an http message, would prob have better result.
            var http = new HttpResponseMessage();

            http.Content = new StringContent(JsonConvert.SerializeObject(response));

            http.Headers.Add(ResponseIdHeader, response.Headers.MessageId);
            http.Headers.Date = response.Headers.CreatedOn;
            //http.Headers.Add(ResponseDateHeader, response.Headers.CreatedOn?.ToString());
            http.Headers.Add(ResponseChannelHeader, response.Headers.SourceChannel);

            var content = http.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();
            var wrapper = new HttpResponseMessageWrapperEx(http, content);

            // TODO: Should probably pass this in to forego the overhead of performing it twice.
            wrapper.RequestWrapper = response.AppRequestMessage.ToTransportRequest();

            return(wrapper);
        }
Exemplo n.º 5
0
        public JsonResult OnPost()
        {
            login_db           _context = new login_db(AppGlobal.get_db_option());
            AppResponseMessage arm      = new AppResponseMessage();

            try {
                using (var transaction = _context.Database.BeginTransaction()) {
                    if (Request.Query["f"] == "register_handler")
                    {
                        string full_name         = Request.Form["full_name"];
                        string email             = Request.Form["email"];
                        string password          = Request.Form["password"];
                        int    full_name_existed = _context.m_user.Where(e => e.full_name == full_name).Count();
                        int    email_existed     = _context.m_user.Where(e => e.email == email).Count();
                        int    count_existed     = full_name_existed + email_existed;
                        if (count_existed > 0)
                        {
                            arm.fail();
                            arm.message = "Data Already Exist!!";
                        }
                        else
                        {
                            m_user m_user_data = new m_user {
                                full_name = full_name,
                                email     = email,
                                password  = password
                            };
                            _context.m_user.Add(m_user_data);
                            _context.SaveChanges();

                            t_login_history login_history = new t_login_history {
                                m_user_id  = m_user_data.m_user_id,
                                login_time = DateTime.Now
                            };

                            _context.t_login_history.Add(login_history);
                            _context.SaveChanges();

                            //jika user valid & aktif
                            var claims = new[] {
                                new Claim(ClaimTypes.Email, email),

                                new Claim("m_user_id", m_user_data.m_user_id.ToString()),
                                new Claim("full_name", m_user_data.full_name),
                                new Claim("history_id", login_history.t_login_history_id.ToString()),
                            };
                            ClaimsIdentity  identity  = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                            ClaimsPrincipal principal = new ClaimsPrincipal(identity);

                            AuthenticationHttpContextExtensions.SignInAsync(HttpContext, CookieAuthenticationDefaults.AuthenticationScheme, principal);

                            arm.success();
                            arm.message = "Success";
                        }
                    }
                    transaction.Commit();
                    _context.SaveChanges();
                }
            } catch (Exception ex) {
                arm.fail();
                arm.message = ex.Message;
            }
            return(new JsonResult(arm)); //return ARM dg method JsonResult untuk auto serialize ke format JSON
        }