Example #1
0
        public ActionResult Index()
        {
            PostViewModel VM = new PostViewModel();

            try
            {
                int        ThreadID = Convert.ToInt32(Session["ThreadID"]);
                RESTResult Result   = new REST(
                    Global.WebAPIBaseURL,
                    "api/Training/RecDB/V1/App/Post/GetPost?ThreadID=" + ThreadID,
                    REST.Method.GET).Result;
                RESTResult Result2 = new REST(
                    Global.WebAPIBaseURL,
                    "api/Training/RecDB/V1/App/Thread/GetOneThread?ThreadID=" + ThreadID,
                    REST.Method.GET).Result;
                if (Result.Success && Result2.Success)
                {
                    VM.ListPost = Result.Deserialize <List <PostModel> >();
                    VM.Thread   = Result2.Deserialize <ThreadModel>();
                    VM.UserID   = Convert.ToInt32(Session["UserID"]);
                    return(View(VM));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(View());
        }
Example #2
0
        public async Task <ActionResult> SendAsync(string Email)
        {
            UserModel User = new UserModel();

            User.Username = Email;
            User.Email    = Email;
            try {
                try {
                    RESTResult Result = new REST(
                        BaseURL: Global.WebAPIBaseURL,
                        URL: "/api/Training/RecDB/V1/App/User/GenerateUserToken",
                        Method: REST.Method.POST,
                        OAuthURL: ConfigurationManager.AppSettings["OAuthBookDB"],
                        Data: User
                        ).Result;
                } catch (Exception ex) {
                    throw ex;
                }
                RESTResult GetToken = new REST(
                    Global.WebAPIBaseURL,
                    "/api/Training/RecDB/V1/App/User/GetUserToken",
                    REST.Method.POST,
                    ConfigurationManager.AppSettings["OAuthBookDB"],
                    User
                    ).Result;
                String      Token   = GetToken.Deserialize <String>();
                MailMessage message = new MailMessage();
                message.To.Add(Email);
                message.Subject = "Reset your password";
                string Address = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/');

                message.Body            = "Please click the link below to reset your password <br> " + Address + "/Password/ResetPassword?e=" + Email + "&q=" + Token;
                message.BodyEncoding    = System.Text.Encoding.UTF8;
                message.From            = new MailAddress("*****@*****.**");
                message.SubjectEncoding = System.Text.Encoding.UTF8;
                message.IsBodyHtml      = true;

                using (var smtp = new SmtpClient()) {
                    var credential = new NetworkCredential {
                        UserName = "******",
                        Password = "******"
                    };
                    smtp.Credentials = credential;
                    smtp.Host        = "smtp.gmail.com";
                    smtp.Port        = 587;
                    smtp.EnableSsl   = true;
                    await smtp.SendMailAsync(message);
                }
            } catch (Exception) {
                return(Content("error"));

                throw;
            }

            return(RedirectToAction("Index", "Login"));
        }
Example #3
0
        public ActionResult Index()
        {
            UserViewModel VM = new UserViewModel();

            try {
                RESTResult Result = new REST(
                    Global.WebAPIBaseURL,
                    "api/Training/RecDB/V1/App/User/GetUnapprovedUser",
                    REST.Method.GET).Result;
                if (Result.Success)
                {
                    VM.ListUser = Result.Deserialize <List <UserModel> >();
                    return(View(VM));
                }
            } catch (Exception ex) {
                throw ex;
            }

            return(View());
        }
Example #4
0
        // GET: Assignment
        public ActionResult Index()
        {
            //if (Session["token"] == null) return RedirectToAction("Index", "Login");

            try
            {
                RESTResult Result = new REST(
                    Global.WebAPIBaseURL,
                    "/api/Training/RecDB/V1/App/Assignment/GetAllAssignment",
                    REST.Method.GET).Result;

                AssignmentViewModel avm = new AssignmentViewModel();
                avm.assignments = Result.Deserialize <List <AssignmentModel> >();


                return(View("Index", avm));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult Index()
        {
            ScheduleViewModel VM = new ScheduleViewModel();

            try
            {
                RESTResult Result = new REST(
                    Global.WebAPIBaseURL,
                    "api/Training/RecDB/V1/App/Schedule/GetAllSchedule",
                    REST.Method.GET).Result;
                if (Result.Success)
                {
                    VM.ListSchedule = Result.Deserialize <List <ScheduleModel> >();
                    return(View(VM));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(View("Index", "Login"));
        }
        public ActionResult Index()
        {
            ThreadViewModel VM = new ThreadViewModel();

            try
            {
                RESTResult Result = new REST(
                    Global.WebAPIBaseURL,
                    "api/Training/RecDB/V1/App/Thread/GetAllThread",
                    REST.Method.GET).Result;
                if (Result.Success)
                {
                    VM.ListThread = Result.Deserialize <List <ThreadModel> >();
                    return(View(VM));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(View());
        }
Example #7
0
        public ActionResult Index(int AssignmentId)
        {
            if (Session["token"] == null)
            {
                return(RedirectToAction("Index", "Login"));
            }

            try
            {
                RESTResult Result = new REST(
                    Global.WebAPIBaseURL,
                    "/api/Training/RecDB/V1/App/Answer/GetAllAnswer?AssignmentID=" + AssignmentId,
                    REST.Method.GET).Result;

                AnswerViewModel avm = new AnswerViewModel();
                avm.answers = Result.Deserialize <List <AnswerModel> >();

                return(View("Index", avm));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #8
0
        public ActionResult ChangeForgottenPassword(string Token, string Email, string Password)
        {
            JsonResult Retdata  = new JsonResult();
            UserModel  UserData = new UserModel {
                Email    = Email,
                Name     = "",
                Password = Password,
                Role     = "",
                Username = Email
            };

            try {
                RESTResult GetUserToken = new REST(
                    Global.WebAPIBaseURL,
                    "/api/Training/RecDB/V1/App/User/GetUserToken",
                    REST.Method.POST,
                    ConfigurationManager.AppSettings["OAuthBookDB"],
                    UserData
                    ).Result;
                String UserToken = GetUserToken.Deserialize <String>();
                if (UserToken.Equals(Token))
                {
                    try {
                        RESTResult Result = new REST(
                            Global.WebAPIBaseURL,
                            "/api/Training/RecDB/V1/App/User/ChangePassword",
                            REST.Method.POST,
                            ConfigurationManager.AppSettings["OAuthBookDB"],
                            UserData
                            ).Result;
                        if (Result.Success)
                        {
                            Retdata = Json(new {
                                Status  = "Success",
                                Message = "Change password success",
                                URL     = Global.BaseURL + "/Login/Index"
                            });
                        }
                        else
                        {
                            Retdata = Json(new {
                                Status  = "Failed",
                                Message = "Change password failed",
                                URL     = Global.BaseURL + "/Login/Index"
                            });
                        }
                        try {
                            RESTResult DeleteUserToken = new REST(
                                Global.WebAPIBaseURL,
                                "/api/Training/RecDB/V1/App/User/DeleteUserToken",
                                REST.Method.POST,
                                ConfigurationManager.AppSettings["OAuthBookDB"],
                                UserData
                                ).Result;
                        } catch (Exception ex) {
                        }
                    } catch (Exception ex) {
                    }
                }
                else
                {
                    Retdata = Json(new {
                        Status  = "Failed",
                        Message = "Invalid token",
                        URL     = Global.BaseURL + "/Login/Index"
                    });
                }
            } catch (Exception ex) {
                throw ex;
            }

            return(Retdata);
        }
Example #9
0
        public ActionResult RegisterAccount(string Name, string Email, string Password)
        {
            JsonResult Retdata = new JsonResult();

            if (Email != "" && Password != "")
            {
                try {
                    UserModel UserData = new UserModel {
                        Email    = Email,
                        Name     = Name,
                        Password = Password,
                        Role     = "unapproved",
                        Username = Email
                    };
                    RESTResult Result = new REST(
                        Global.WebAPIBaseURL,
                        "/api/Training/RecDB/V1/App/User/RegisterUser",
                        REST.Method.POST,
                        ConfigurationManager.AppSettings["OAuthBookDB"],
                        UserData
                        ).Result;
                    if (Result.Success)
                    {
                        UserModel User = Result.Deserialize <UserModel>();

                        if (User != null)
                        {
                            Retdata = Json(new {
                                Status  = "Success",
                                Message = "Regis Success",
                                URL     = Global.BaseURL
                            });
                        }
                        else
                        {
                            Retdata = Json(new {
                                Status  = "Failed",
                                Message = "User not found"
                            });
                        }
                    }
                    else
                    {
                        Retdata = Json(new {
                            Status  = "Failed",
                            Message = Result.Message
                        });
                    }
                } catch (Exception ex) {
                    Retdata = Json(new {
                        Status  = "Failed",
                        Message = ex.Message
                    });
                }
            }
            else
            {
                Retdata = Json(new {
                    Status  = "Failed",
                    Message = "Username or Password cannot be empty"
                });
            }

            Retdata.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return(Retdata);
        }
Example #10
0
        public ActionResult Auth(string Username, string Password)
        {
            JsonResult Retdata;

            if (Username != "" && Password != "")
            {
                try
                {
                    AuthUser UserData = new AuthUser();
                    UserData.Email    = Username;
                    UserData.Username = Username;
                    UserData.Password = Password;

                    RESTResult Result = new REST(
                        Global.WebAPIBaseURL,
                        "/api/Training/RecDB/V1/App/User/GetUserLogin",
                        REST.Method.POST,
                        ConfigurationManager.AppSettings["OAuthBookDB"],
                        UserData
                        ).Result;

                    if (Result.Success)
                    {
                        UserModel User = Result.Deserialize <UserModel>();

                        if (User != null)
                        {
                            Session["UserID"] = User.UserID;
                            Session["Role"]   = User.Role;
                            Session["Email"]  = User.Email;
                            Session["Name"]   = User.Name;
                            if (User.Role.Equals("unapproved"))
                            {
                                Retdata = Json(new {
                                    Status  = "Failed",
                                    Message = "Please wait for your verification"
                                });
                            }
                            else
                            {
                                Retdata = Json(new {
                                    Status  = "Success",
                                    Message = "Login Success",
                                    URL     = Global.BaseURL + "/Thread/Index"
                                });
                            }
                        }
                        else
                        {
                            Retdata = Json(new
                            {
                                Status  = "Failed",
                                Message = "User not found"
                            });
                        }
                    }
                    else
                    {
                        Retdata = Json(new {
                            Status  = "Failed",
                            Message = "User not found"
                        });
                    }
                }
                catch (Exception ex)
                {
                    Retdata = Json(new
                    {
                        Status  = "Failed",
                        Message = ex.Message
                    });
                }
            }
            else
            {
                Retdata = Json(new
                {
                    Status  = "Failed",
                    Message = "Username or Password cannot be empty"
                });
            }

            Retdata.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return(Retdata);
        }