예제 #1
0
        /*
         * Metod för att lägga till moderatorsbehörigheter.
         * Metodens inparameter är det Id som tillhör den specifika användare som ska tilldelas moderatorsbehörigheter.
         */
        public ActionResult AddPermission(int id)
        {
            Models.AdminModel sessionObjekt = (Models.AdminModel)Session["admin"];

            if (Session["admin"] == null)
            {
                return(RedirectToAction("LoginPage", "Login"));
            }
            else
            {
                ViewBag.Username = "******" + sessionObjekt.username;
            }
            try
            {
                // Anrop till webservicen
                LoginService.LoginServiceClient client = new LoginService.LoginServiceClient();
                if (client.AssignModeratorRole(id) == true)
                {
                    // Anrop till webservicens metod för att tilldela moderatorsbehörigheter, där vi skickar med den specifika användarens Id
                    client.AssignModeratorRole(id);
                }
                // När behörigheten är tilldelad, återvänd till sidan som visar alla aktiva användare
                return(RedirectToAction("ActiveUsers"));
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Home", "ActiveUsers")));
            }
        }
예제 #2
0
        // Metod för att radera en användare, tar den specifika användarens Id som inparamteter
        public ActionResult Delete(int id)
        {
            Models.AdminModel sessionObjekt = (Models.AdminModel)Session["admin"];

            if (Session["admin"] == null)
            {
                return(RedirectToAction("LoginPage", "Login"));
            }
            else
            {
                ViewBag.Username = "******" + sessionObjekt.username;
            }
            try
            {
                // Anrop till webservicen
                UserService.UserProfileServiceClient client = new UserService.UserProfileServiceClient();
                if (client.GetUserByUserId(id) != null)
                {
                    // Anrop till webservicens metod för att hitta en specifik användare och visa upp en vy utifrån detta
                    return(View(client.GetUserByUserId(id)));
                }
                else
                {
                    ModelState.AddModelError("Felmeddelande", "Denna användare kan inte hittas.");
                    return(View());
                }
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Home", "ActiveUsers")));
            }
        }
예제 #3
0
        // Metod för att visa alla flaggade ärenden
        public ActionResult FlaggedErrands()
        {
            Models.AdminModel sessionObjekt = (Models.AdminModel)Session["admin"];

            if (Session["admin"] == null)
            {
                return(RedirectToAction("LoginPage", "Login"));
            }
            else
            {
                ViewBag.Username = "******" + sessionObjekt.username;
            }
            try
            {
                // Anrop till webservicen
                // Om flaggade ärenden kan hittas
                LoginService.LoginServiceClient client = new LoginService.LoginServiceClient();
                if (client.GetFlaggedUsers() != null)
                {
                    // Anrop till webservicens metod för att visa alla flaggade ärenden
                    return(View(client.GetFlaggedUsers()));
                }
                // Om flaggade ärenden inte kan hittas, skriv ut ett felmeddelande
                else
                {
                    ModelState.AddModelError("Felmeddelande", "Inga flaggade användare just nu.");
                    return(View());
                }
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Home", "ActiveUsers")));
            }
        }
예제 #4
0
        // Metod för att visa alla blockade användare
        public ActionResult BlockedUsers()
        {
            Models.AdminModel sessionObjekt = (Models.AdminModel)Session["admin"];

            if (Session["admin"] == null)
            {
                return(RedirectToAction("LoginPage", "Login"));
            }
            else
            {
                ViewBag.Username = "******" + sessionObjekt.username;
            }
            try
            {
                // Anrop till webservicen
                LoginService.LoginServiceClient client = new LoginService.LoginServiceClient();
                if (client.GetBlockedUsers() != null)
                {
                    // Anrop till webservicens metod för att visa alla blockade användare
                    return(View(client.GetBlockedUsers()));
                }
                else
                {
                    ModelState.AddModelError("Felmeddelande", "No blocked users, good for us!");
                    return(View());
                }
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Home", "ActiveUsers")));
            }
        }
예제 #5
0
        private List <Models.AdminModel> ConvertToAdminList(DataTable dataTable)
        {
            if (dataTable == null || dataTable.Rows.Count < 1)
            {
                return(null);
            }
            List <Models.AdminModel> modelList = new List <Models.AdminModel>();

            foreach (DataRow row in dataTable.Rows)
            {
                Models.AdminModel admin = new Models.AdminModel();
                if (row["user_id"] != null && row["user_id"].ToString() != "")
                {
                    admin.user_id = row["user_id"].ToString();
                }
                if (row["user_account"] != null && row["user_account"].ToString() != "")
                {
                    admin.user_account = row["user_account"].ToString();
                }
                if (row["user_pwd"] != null && row["user_pwd"].ToString() != "")
                {
                    admin.user_pwd = row["user_pwd"].ToString();
                }
                if (row["mobile"] != null && row["mobile"].ToString() != "")
                {
                    admin.mobile = row["mobile"].ToString();
                }
                if (row["real_name"] != null && row["real_name"].ToString() != "")
                {
                    admin.real_name = row["real_name"].ToString();
                }
                modelList.Add(admin);
            }
            return(modelList);
        }
예제 #6
0
        // Metod för att visa alla moderatorer
        public ActionResult Moderators()
        {
            Models.AdminModel sessionObjekt = (Models.AdminModel)Session["admin"];

            if (Session["admin"] == null)
            {
                return(RedirectToAction("LoginPage", "Login"));
            }
            else
            {
                ViewBag.Username = "******" + sessionObjekt.username;
            }
            try
            {
                // Anrop till webservicen
                LoginService.LoginServiceClient client = new LoginService.LoginServiceClient();
                // Om moderatorer finns
                if (client.GetModerators() != null)
                {
                    // Anrop till webservicens metod för att visa alla moderatorer
                    return(View(client.GetModerators()));
                }
                // Om moderatorer inte finns, skriv ut ett felmeddelande
                else
                {
                    ModelState.AddModelError("Felmeddelande", "Det verkar inte finnas några moderatorer just nu.");
                    return(View());
                }
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Home", "ActiveUsers")));
            }
        }
예제 #7
0
        /*
         * Metod för att radera moderatorsbehörigheter.
         * Metodens inparameter är ID:t som tillhör den specifika användare vars behörighet ska raderas.
         */
        public ActionResult DeletePermission(int id)
        {
            Models.AdminModel sessionObjekt = (Models.AdminModel)Session["admin"];

            if (Session["admin"] == null)
            {
                return(RedirectToAction("LoginPage", "Login"));
            }
            else
            {
                ViewBag.Username = "******" + sessionObjekt.username;
            }
            try
            {
                // Anrop till webservicen
                LoginService.LoginServiceClient client = new LoginService.LoginServiceClient();
                if (client.AssignUserRole(id) == true)
                {
                    // Här ropas på webserivcens metod för att ta bort moderator behörigheter och göra användaren till en vanlig användare
                    client.AssignUserRole(id);
                    // När behörigheten är raderad, återvänd till sidan som visar alla moderatorer
                    return(RedirectToAction("Moderators"));
                }
                else
                {
                    ModelState.AddModelError("Felmeddelande", "Användaren har ingen moderator behörighet");
                    return(View());
                }
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Home", "ActiveUsers")));
            }
        }
예제 #8
0
        public Models.AdminModel AdminLogin(Models.AdminModel adminInfo, ref string reason)
        {
            try
            {
                string  sql = "select user_id,user_account,user_pwd,mobile,real_name from SystemUser where user_account='" + adminInfo.user_account + "'";
                DataSet ds  = SqlHelper.ExecuteDataSet(CommandType.Text, sql, null);
                if (ds == null || ds.Tables.Count < 1)
                {
                    reason = "用户不存在";
                    return(null);
                }

                List <WebAPI.Models.AdminModel> AdminList = ConvertToAdminList(ds.Tables[0]);
                if (AdminList == null || AdminList.Count < 1)
                {
                    reason = "用户不存在";
                    return(null);
                }

                if (adminInfo.user_pwd != AdminList[0].user_pwd)
                {
                    reason = "密码不正确";
                    return(null);
                }

                return(AdminList[0]);
            }
            catch (Exception e)
            {
                reason = e.Message;
                return(null);
            }
        }
예제 #9
0
        public ActionResult Index()
        {
            Models.AdminModel sessionObjekt = (Models.AdminModel)Session["admin"];
            // Om admin ej är inloggad, gå till inloggningssidan

            if (Session["admin"] == null)
            {
                return(RedirectToAction("LoginPage", "Login"));
            }
            else
            {
                ViewBag.Username = "******" + sessionObjekt.username;
            }
            try
            {
                LoginService.LoginServiceClient client = new LoginService.LoginServiceClient();

                int ActiveRow  = client.CountActiveUsers();
                int FlaggedRow = client.CountFlaggedUsers();
                int BlockedRow = client.CountBlockedUsers();

                Models.StatisticModel statisticModel = new Models.StatisticModel();

                statisticModel.ActiveRow  = ActiveRow;
                statisticModel.BlockedRow = BlockedRow;
                statisticModel.FlaggedRow = FlaggedRow;


                return(View(statisticModel));
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Home", "ActiveUsers")));
            }
        }
예제 #10
0
 public ActionResult Main()
 {
     Models.AdminModel admin = Session["Admin"] as Models.AdminModel;
     if (admin == null)
     {
         Response.Redirect("/Home/Index");
     }
     return(View());
 }
예제 #11
0
 public JsonResult AddAdmin(Models.AdminModel model)
 {
     if (ModelState.IsValid)
     {
         IDAL.IAdminRepository adminRepository = EnterRepository.GetRepositoryEnter().GetAdminRepository;
         //判断权限名称是否已存在
         var result = adminRepository.LoadEntities(m => m.Mobile == model.Mobile.Trim()).FirstOrDefault();
         if (result == null)
         {
             Random rn   = new Random();
             string salt = rn.Next(10000, 99999).ToString() + rn.Next(10000, 99999).ToString();
             adminRepository.AddEntity(new Model.Admin()
             {
                 AuthoryId     = model.AuthoryId,
                 CreateTime    = DateTime.Now,
                 IsLogin       = model.IsLogin,
                 Mobile        = model.Mobile,
                 IsSuperAdmin  = 0,
                 LastLoginTime = DateTime.Now,
                 Salt          = salt,
                 Password      = MD5Helper.CreatePasswordMd5("ad" + model.Mobile.Substring(7, 4), salt)
             });
             //添加下操作记录
             PublicFunction.AddOperation(1, string.Format("添加管理员"), string.Format("添加管理员=={0}==成功", model.Mobile));
             if (EnterRepository.GetRepositoryEnter().SaveChange() > 0)
             {
                 return(Json(new
                 {
                     state = "success",
                     message = "添加管理员成功"
                 }));
             }
             else
             {
                 PublicFunction.AddOperation(1, string.Format("添加管理员"), string.Format("添加管理员=={0}==失败", model.Mobile));
                 EnterRepository.GetRepositoryEnter().SaveChange();
                 return(Json(new
                 {
                     state = "error",
                     message = "添加管理员失败"
                 }));
             }
         }
         else
         {
             return(Json(new
             {
                 state = "error",
                 message = "手机号码已经存在了"
             }));
         }
     }
     else
     {
         return(Json(new { state = "error", message = "信息不完整" }));
     }
 }
예제 #12
0
 // GET: Admin
 public async Task <ActionResult> Index()
 {
     AssurBox.Samples.API.Insurance.Models.AdminModel model = new Models.AdminModel();
     using (DAL.ApiDataContext ctx = new DAL.ApiDataContext())
     {
         model.Requests = await ctx.CarGreenCardRequests.AsNoTracking()
                          .OrderByDescending(x => x.RequestDate).Take(200).ToListAsync();
     }
     return(View(model));
 }
예제 #13
0
 public JsonResult UpdateAdmin(Models.AdminModel model)
 {
     if (ModelState.IsValid)
     {
         IDAL.IAdminRepository adminRepository = EnterRepository.GetRepositoryEnter().GetAdminRepository;
         //判断权限名称是否已存在
         var result = adminRepository.LoadEntities(m => m.Mobile == model.Mobile.Trim()).FirstOrDefault();
         if (result != null && result.Id != model.Id)
         {
             return(Json(new
             {
                 state = "error",
                 message = "手机号码已经存在了"
             }));
         }
         else
         {
             Model.Admin admin = new Model.Admin()
             {
                 AuthoryId = model.AuthoryId,
                 IsLogin   = model.IsLogin,
                 Mobile    = model.Mobile,
                 Id        = model.Id
             };
             //清楚context中result对象
             adminRepository.Get(m => m.Id == model.Id);
             adminRepository.EditEntity(admin, new string[] { "AuthoryId", "IsLogin", "Mobile" });
             PublicFunction.AddOperation(1, string.Format("修改管理员"), string.Format("修改管理员=={0}==成功", model.Mobile));
             if (EnterRepository.GetRepositoryEnter().SaveChange() > 0)
             {
                 return(Json(new
                 {
                     state = "success",
                     message = "修改管理员成功"
                 }));
             }
             else
             {
                 PublicFunction.AddOperation(1, string.Format("修改管理员"), string.Format("修改管理员=={0}==失败", model.Mobile));
                 EnterRepository.GetRepositoryEnter().SaveChange();
                 return(Json(new
                 {
                     state = "error",
                     message = "修改管理员失败"
                 }));
             }
         }
     }
     else
     {
         return(Json(new { state = "error", message = "信息不完整" }));
     }
 }
예제 #14
0
        // Metod för att radera en användare, tar den specifika användarens Id som inparamteter
        public ActionResult BlockUser(int id)
        {
            Models.AdminModel sessionObjekt = (Models.AdminModel)Session["admin"];
            if (Session["admin"] == null)
            {
                return(RedirectToAction("LoginPage", "Login"));
            }
            else
            {
                ViewBag.Username = "******" + sessionObjekt.username;
            }
            try
            {
                // Anrop till webservicen
                UserService.UserProfileServiceClient client = new UserService.UserProfileServiceClient();
                if (client.GetUserByUserId(id) != null)
                {
                    Models.Userobjekt userobjekt = new Models.Userobjekt();

                    userobjekt.user = client.GetUserByUserId(id);

                    /*userobjekt.ID = client.GetUserByUserId(id).Id;
                     * userobjekt.name = client.GetUserByUserId(id).Name;
                     * userobjekt.surname = client.GetUserByUserId(id).Surname;
                     * userobjekt.city = client.GetUserByUserId(id).City;
                     * userobjekt.adress = client.GetUserByUserId(id).Address;
                     * userobjekt.phonenumber = client.GetUserByUserId(id).Phonenumber;
                     * userobjekt.username = client.GetUserByUserId(id).Username;
                     * userobjekt.email = client.GetUserByUserId(id).Email;
                     * userobjekt.picture = client.GetUserByUserId(id).Picture;*/

                    Models.ViewModel viewModel = new Models.ViewModel();
                    viewModel.userID     = userobjekt.user.Id;
                    viewModel.userObjekt = userobjekt;

                    // Anrop till webservicens metod för att hitta en specifik användare och visa upp en vy utifrån detta
                    return(View(viewModel));
                }
                else
                {
                    ModelState.AddModelError("Felmeddelande", "Denna användare kan inte hittas.");
                    return(View());
                }
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Home", "ActiveUsers")));
            }
        }
예제 #15
0
        public ActionResult LoginPage(string username, string password)
        {
// Anrop till webservicen
            LoginService.LoginServiceClient klient = new LoginService.LoginServiceClient();

/*
 * Variabel för att kolla om inloggningen är godkänd.
 * Variabelns värde är lika med ett anrop på Login-metoden i webservicen och vi skickar dessutom med användarnamn och lösenord vid anropet.
 */
            bool response = klient.AdminLogin(username, password);

            // Om inloggningen är godkänd, dvs att responce-variabeln är true
            if (response)

            {
                /*
                 * Här skapas ett objekt som tilldelas värdena av en användares Id, Email och användarnamn.
                 * Dessa data hämtas från webservicen.
                 */
                Models.AdminModel sessionObjekt = new Models.AdminModel();
                sessionObjekt.email    = klient.GetAdminByUsername(username).Email;
                sessionObjekt.ID       = klient.GetAdminByUsername(username).ID;
                sessionObjekt.username = klient.GetAdminByUsername(username).Username;
                // De olika värdena lagras i en array
                Session["admin"] = sessionObjekt;

                //  ViewBag.Username = "******" + sessionObjekt.username;

                // Flytta användaren från login-sidan
                System.Web.Security.FormsAuthentication.RedirectFromLoginPage(username, false);
                // När inloggningen är klar hamnar användaren på förstasidan, nu som inloggad admin
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                // Om inloggningen inte gick så bra visas ett felmeddelande

                ModelState.AddModelError("Felmeddelande", "Inloggningen misslyckades");

                return(View());
            }

            // Session["Username"] = "******" + data;
        }
예제 #16
0
        /*
         * Metod för att bekräfta radering av en användare, här utförs således den faktiska raderingen.
         * Metoden tar den specifika användarens Id som inparamter.
         */
        public ActionResult ConfirmDelete(int id)
        {
            Models.AdminModel sessionObjekt = (Models.AdminModel)Session["admin"];

            if (Session["admin"] == null)
            {
                return(RedirectToAction("LoginPage", "Login"));
            }
            else
            {
                ViewBag.Username = "******" + sessionObjekt.username;
            }
            try
            {
                UserService.UserProfileServiceClient client  = new UserService.UserProfileServiceClient();
                LoginService.LoginServiceClient      client2 = new LoginService.LoginServiceClient();

                if (client.UserIdExistsInProfile(id) == true)
                {
                    client.DeleteUser(id);
                    client2.DeleteUser(id);
                }

                else
                {
                    client2.DeleteUser(id);
                }

                // Anrop till webservicen
                // Anrop till webservicens metod för att radera en användare, där vi skickar me med den specifika användarens Id
                // När raderingen slutförs, återvänd till sidan som visar alla aktiva användare
                ModelState.AddModelError("Felmeddelande", "Konto raderat!");
                return(RedirectToAction("ActiveUsers"));
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Home", "ActiveUsers")));
            }
        }
예제 #17
0
        public JsonResult AdminLogin(WebAPI.Models.AdminModel adminInfo)
        {
            JsonResult resultJson = new JsonResult();

            if (adminInfo == null)
            {
                var returnData = new { result = false, reason = "参数不正确" };
                resultJson.Data = returnData;
                return(resultJson);
            }

            string verifyCode = Session["SessionVerifyCode"].ToString();

            if (verifyCode.ToLower() != adminInfo.verifyCode.ToLower())
            {
                var returnData = new { result = false, reason = "验证码不正确" };
                resultJson.Data = returnData;
                return(resultJson);
            }


            string reason = string.Empty;

            Models.AdminModel currentAdmin = WebAPI.Data.UserData.Instance.AdminLogin(adminInfo, ref reason);
            if (!string.IsNullOrEmpty(reason))
            {
                var data = new { result = false, reason = reason };
                resultJson.Data = data;
                return(resultJson);
            }

            Session["Admin"] = currentAdmin;

            var successData = new { result = true, reason = reason };

            resultJson.Data = successData;
            return(resultJson);
        }
예제 #18
0
        public ActionResult Register(FormCollection collection)
        {
            try
            {
                MVCFinal.Models.AdminModel Usuario = new Models.AdminModel();

                Usuario.Ci       = Convert.ToString(collection["Ci"]);
                Usuario.Email    = Convert.ToString(collection["Email"]);
                Usuario.Nombre   = Convert.ToString(collection["Nombre"]);
                Usuario.Usuario  = Convert.ToString(collection["Usuario"]);
                Usuario.Password = Convert.ToString(collection["Password"]);



                CreoServicio().AltaUsuario(convertirModelAdmin(Usuario));

                return(View(Usuario));
            }
            catch
            {
                return(View());
            }
        }
예제 #19
0
        // Metod för att visa en profil, tar en användares Id som inparameter för att kunna visa denna specifika profil
        public ActionResult ShowProfile(int id)
        {
            Models.AdminModel sessionObjekt = (Models.AdminModel)Session["admin"];
            if (Session["admin"] == null)
            {
                return(RedirectToAction("LoginPage", "Login"));
            }
            else
            {
                ViewBag.Username = "******" + sessionObjekt.username;
            }
            try
            {
                // Anrop till webservicen
                UserService.UserProfileServiceClient client = new UserService.UserProfileServiceClient();

                if (client.GetUserByUserId(id) != null)
                {
                    Models.Userobjekt userobjekt            = new Models.Userobjekt();
                    LoginService.LoginServiceClient client2 = new LoginService.LoginServiceClient();

                    userobjekt.StatusId = client2.GetUserById(id).ID;
                    // Vy som använder sig av en metod från webservicen för att hitta en specifik användare
                    userobjekt.user = client.GetUserByUserId(id);
                    return(View(userobjekt));
                }
                else
                {
                    ModelState.AddModelError("Felmeddelande", "Ingen profil att visa här");
                    return(View());
                }
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Home", "ActiveUsers")));
            }
        }