示例#1
0
 public ActionResult Logar(string Login, string Password, int?id)
 {
     try
     {
         using (RepositoryUser rep = new RepositoryUser())
         {
             Func <UserEntity, bool> predicate = (u => u.Login == Login && u.Password == Password);
             UserEntity user = rep.Get(predicate).FirstOrDefault();
             if (user == null)
             {
                 ViewData["Error"] = "Login e/ou senha inválidos.";
                 return(View("Login"));
             }
             user.Password     = String.Empty;
             Session["ID"]     = user.ID;
             Session["Login"]  = user.Login;
             Session["Nome"]   = user.First_name + " " + user.Last_name;
             Session["Logado"] = "logado";
             if (id != null)
             {
                 return(RedirectToAction("AdicionarCarrinho", "Cart", new { id }));
             }
             return(RedirectToAction("Index", "Product"));
         }
     }
     catch (Exception)
     {
         ViewBag.Error = "Login e/ou senha incorretos. Verifique!";
         return(View("Index"));
     }
 }
示例#2
0
文件: TestUsers.cs 项目: 3IE/todo-api
        public async void Delete_user_in_db()
        {
            var context = GetContext();
            var access  = new RepositoryUser(context);
            var bm      = new UserServices(access);

            try
            {
                await bm.Create(new Users { Username = "******" }, "test");

                await bm.Create(new Users { Username = "******" }, "test");

                await bm.DeleteUser(1);

                var users = await bm.GetAllUsers();

                ICollection <Users> userList = users as ICollection <Users>;
                Assert.Equal(1, userList.Count);
                Assert.Equal("user2", userList.First().Username);
            }
            finally
            {
                context.Dispose();
            }
        }
示例#3
0
        protected void update_Click(object sender, EventArgs e)
        {
            Int32 myid = 0;

            Int32.TryParse(id.Text.ToString(), out myid);
            Int32 roleid = 0;
            bool  cek    = RepositoryUser.cekID(myid);

            if (cek)
            {
                Int32.TryParse(RepositoryUser.FindID(myid).RoleID.ToString(), out roleid);
                if (RepositoryUser.FindID(myid).Email != Session["Email"].ToString())
                {
                    if (roleid == 2)
                    {
                        RepositoryUser.ChangeToAdmin(myid);
                    }
                    else if (roleid == 1)
                    {
                        RepositoryUser.ChangeToMember(myid);
                    }
                }
                else
                {
                    Response.Write("<script>alert('Can not change current login admin role.')</script>");
                }
                refresh();
            }
            else
            {
                Response.Write("<script>alert('ID does not exists.')</script>");
            }
        }
 public HttpResponseMessage GetAll(HttpRequestMessage request)
 {
     using (RepositoryUser rep = new RepositoryUser())
     {
         return(request.CreateResponse <ICollection <UserEntity> >(HttpStatusCode.Accepted, rep.GetAll().ToList()));
     }
 }
示例#5
0
        public ActionResult Delete(UserMD Data)
        {
            RepositoryUser repo = new RepositoryUser();
            OperationResult <UserViewModel> result = repo.Delete(Data);

            return(Json(result));
        }
示例#6
0
文件: TestUsers.cs 项目: 3IE/todo-api
        public async void Update_user_correctly()
        {
            var context = GetContext();
            var access  = new RepositoryUser(context);
            var bm      = new UserServices(access);

            try
            {
                await bm.Create(new Users { Username = "******" }, "test");

                await bm.UpdateUser(new Users { Id = 1, Username = "******" }, "test");

                var updatedUser = await bm.GetById(1);

                Assert.Equal("user2", updatedUser.Username);
            }
            catch
            {
                Assert.True(false);
                context.Dispose();
            }
            finally
            {
                context.Dispose();
            }
        }
示例#7
0
        protected void updateprofile_Click(object sender, EventArgs e)
        {
            String email = emailfield.Text.ToString();
            String name  = namefield.Text.ToString();
            String gender;
            String oldemail = Session["Email"].ToString();

            if (RB1.Checked)
            {
                gender = RB1.Text.ToString();
            }
            else if (RB2.Checked)
            {
                gender = RB2.Text.ToString();
            }
            else
            {
                gender = "";
            }
            bool cekInput = cek(email, name, gender);

            if (cekInput)
            {
                Session["Email"]    = email;
                Session["UserName"] = name;
                RepositoryUser.UpdateProfile(oldemail, email, name, gender);
                Response.Redirect("ProfileMemberPage.aspx");
            }
            else
            {
                Response.Write("<script>alert('Data can not be null.')</script>");
            }
        }
示例#8
0
        // 員工管理首頁
        public ActionResult Index()
        {
            RepositoryUser       repo = new RepositoryUser();
            List <UserViewModel> data = repo.Query();

            return(View(data));
        }
        /// <summary>
        /// Creates a new repository for a given user
        /// </summary>
        /// <param name="id"></param>
        /// <param name="repository"></param>
        /// <returns></returns>
        public bool CreateRepositoryForUser(Guid userId, Repository repository)
        {
            var user = Context.Users.FirstOrDefault(u => u.Id == userId);

            if (user == null)
            {
                return(false);
            }

            // already attached - just return
            if (Context.UserRepositories.Any(ur => ur.UserId == userId && ur.RepositoryId == repository.Id))
            {
                return(true);
            }

            var map = new RepositoryUser()
            {
                UserId     = user.Id,
                Repository = repository,
                UserType   = RepositoryUserTypes.Owner
            };

            user.Repositories.Add(map);

            return(Save());
        }
示例#10
0
        public void ResetPassword(int ID)
        {
            var objRepo     = new RepositoryUser();
            var dataUsuario = objRepo.Get(ID);

            if (dataUsuario == null)
            {
                throw new Exception("UserInvalid");
            }

            var NewPassword = GeneratePassword(8);

            dataUsuario.Password       = new BusinessCryptoMD5(GlobalConfiguration.CryptoKey).CryptoString(NewPassword);
            dataUsuario.ChangePassword = true;

            objRepo.Update(dataUsuario);

            List <string> arr = new List <string>();

            arr.Add(dataUsuario.Email);

            var objAlerta = new BusinessNotification();

            byte[] outMessage = new byte[ResourceMessage.GetStream("NotificationRecoveryBodyContent").Length];
            ResourceMessage.GetStream("NotificationRecoveryBodyContent").Read(outMessage, 0, (int)ResourceMessage.GetStream("NotificationRecoveryBodyContent").Length);

            StringBuilder sb = new StringBuilder(UnicodeEncoding.Unicode.GetString(outMessage));

            sb = sb.Replace("#%Nombre%#", dataUsuario.Name);
            sb = sb.Replace("#%ClaveTemporal%#", NewPassword);

            //objAlerta.SendMails(arr, ResourceMessage.GetString("NotificationRecoveryPassword"), sb.ToString());
            objAlerta.SendMailExchange(GlobalConfiguration.exchangeUser, GlobalConfiguration.exchangePwd, arr, ResourceMessage.GetString("NotificationRecoveryPassword"), sb.ToString());
        }
示例#11
0
        protected void changebutton_Click(object sender, EventArgs e)
        {
            String oldpass  = oldpassword.Text.ToString();
            String newpass  = newpassword.Text.ToString();
            String confpass = confirmpassword.Text.ToString();
            bool   cekPW    = RepositoryUser.cekPass(oldpass);

            if (cekPW)
            {
                if (validation(newpass))
                {
                    if (newpass == confpass)
                    {
                        RepositoryUser.InsertNewPassword(oldpass, newpass);
                        Response.Redirect("ProfileMemberPage.aspx");
                    }
                    else
                    {
                        Response.Write("<script>alert('Your new password does not match with the confirmation password !')</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('New password must atleast consists of 5 words.')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('Your old password does not match with your current login password !')</script>");
            }
        }
示例#12
0
        protected void _allUser_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "changestatus")
            {
                Int32  id     = Int32.Parse(e.CommandArgument.ToString());
                String status = _allUser.Rows[id].Cells[5].Text.ToString();
                String email  = _allUser.Rows[id].Cells[3].Text.ToString();

                if (RepositoryUser.Email(email).Email != Session["Email"].ToString())
                {
                    if (status == "Active")
                    {
                        RepositoryUser.ChangeToBlocked(email);
                    }
                    else if (status == "Blocked")
                    {
                        RepositoryUser.ChangeToActive(email);
                    }
                }
                else
                {
                    Response.Write("<script>alert('Can not change current login admin status.')</script>");
                }
            }
            refresh();
        }
示例#13
0
 private void RegisterNew(DtoUser user)
 {
     using (RepositoryUser model = new RepositoryUser())
     {
         model.Create(user);
     }
 }
示例#14
0
 public ActionResult Index()
 {
     using (Repository <UserEntity> rep = new RepositoryUser())
     {
         return(View(rep.GetAll().ToList()));
     }
 }
        public ModelViewUser Update(ModelViewUser model)
        {
            var objRepository = new RepositoryUser();

            var dataOld = new RepositoryUser().Get(model.UserID);

            EntityUser data = new EntityUser()
            {
                UserID           = model.UserID,
                ProfileID        = model.ProfileID,
                UserName         = model.UserName,
                Name             = model.Name,
                Password         = dataOld.Password,
                Token            = dataOld.Token,
                ChangePassword   = dataOld.ChangePassword,
                Email            = model.Email,
                Status           = dataOld.Status,
                DateLastAccess   = dataOld.DateLastAccess,
                DateCreate       = dataOld.DateCreate,
                DateModification = DateTime.UtcNow
            };

            data = objRepository.Update(data);

            return(model);
        }
示例#16
0
        // 刪除
        public ActionResult Delete(long RecordID)
        {
            RepositoryUser repo = new RepositoryUser();
            UserMD         data = repo.GetUserMD(RecordID);

            return(data == null?PartialView("_Error") : PartialView("_Delete", data));
        }
示例#17
0
        public void ChangePassword(ModelViewChangePassword model)
        {
            if (model.TokenApp != GlobalConfiguration.TokenWEB)
            {
                if (model.TokenApp != GlobalConfiguration.TokenMobile)
                {
                    throw new Exception("TokenInvalid");
                }
            }

            var objRepo     = new RepositoryUser();
            var dataUsuario = objRepo.GetToken(model.TokenUser);

            if (dataUsuario.Password != new BusinessCryptoMD5(GlobalConfiguration.CryptoKey).CryptoString(model.OldPassword))
            {
                throw new Exception("PasswordOldInvalid");
            }

            if (model.NewPassword != model.ConfirmPassword)
            {
                throw new Exception("ConfirmPassword");
            }

            dataUsuario.Password       = new BusinessCryptoMD5(GlobalConfiguration.CryptoKey).CryptoString(model.NewPassword);
            dataUsuario.ChangePassword = false;

            objRepo.Update(dataUsuario);
        }
示例#18
0
文件: TestUsers.cs 项目: 3IE/todo-api
        public async void Update_user_no_password()
        {
            var context = GetContext();
            var access  = new RepositoryUser(context);
            var bm      = new UserServices(access);

            try
            {
                await bm.Create(new Users { Username = "******" }, "test");

                await bm.Create(new Users { Username = "******" }, "test");

                await bm.UpdateUser(new Users { Username = "******" }, "");

                Assert.True(false);
            }
            catch
            {
                Assert.True(true);
                context.Dispose();
            }
            finally
            {
                context.Dispose();
            }
        }
示例#19
0
        // 詳細資訊
        public ActionResult Detail(long RecordID)
        {
            RepositoryUser repo = new RepositoryUser();
            UserViewModel  data = repo.GetUserViewModel(RecordID);

            return(data == null?PartialView("_Error") : PartialView("_Detail", data));
        }
示例#20
0
 public HomeController()
 {
     _repQues  = new RepositoryQuestion("", DbType.SqLite);
     _repoTag  = new RepositoryTag("", DbType.SqLite);
     _repoSet  = new RepositorySetting("", DbType.SqLite);
     _repoIst  = new RepositoryQuestionVisit("", DbType.SqLite);
     _repoUser = new RepositoryUser("", DbType.SqLite);
 }
示例#21
0
        // 帳號設定首頁
        public ActionResult Index()
        {
            RepositoryUser repo = new RepositoryUser();
            AuthModel      auth = RepositoryAuthModel.GetAuthModel(HttpContext.User.Identity as FormsIdentity);
            UserViewModel  data = repo.GetUserViewModel(auth.ID);

            return(data == null?View("Error") : View(data));
        }
示例#22
0
        public ActionResult Update(UserMD Data)
        {
            RepositoryUser repo = new RepositoryUser();
            AuthModel      user = RepositoryAuthModel.GetAuthModel(HttpContext.User.Identity as FormsIdentity);
            OperationResult <UserViewModel> result = repo.Update(Data, user, true);

            return(Json(result));
        }
示例#23
0
        public async Task <DataContext> InitTodoTest()
        {
            var context = GetContext();
            var access  = new RepositoryUser(context);
            var bm      = new UserServices(access);
            await bm.Create(new Users { Username = "******" }, "test");

            return(context);
        }
示例#24
0
 public SoruController()
 {
     _repoAns     = new RepositoryAnswers("", DbType.SqLite);
     _repoQues    = new RepositoryQuestion("", DbType.SqLite);
     _repoTag     = new RepositoryTag("", DbType.SqLite);
     _repoUser    = new RepositoryUser("", DbType.SqLite);
     _repoIst     = new RepositoryQuestionVisit("", DbType.SqLite);
     _repoQuesTag = new RepositoryQuestionTag("", DbType.SqLite);
 }
示例#25
0
        public int SetupUser()
        {
            var repos = new RepositoryUser(_uow);

            if (!repos.CheckIfUserExists(this.GetHostName()))
            {
                repos.CreatUser(this.GetHostName());
            }
            return(repos.GetUserId(this.GetHostName()));
        }
示例#26
0
 public ManagerCategory(IHttpContextAccessor httpContextAccessor,
                        ILoggerFactory logger,
                        RepositoryRole repositoryRole,
                        RepositoryUser repositoryUser,
                        ManagerUser managerUser,
                        IMapper mapper,
                        IRepositoryCategory repositoryCategory) : base(httpContextAccessor, logger, repositoryRole, repositoryUser, managerUser, mapper)
 {
     _repositoryCategory = repositoryCategory;
 }
 public AirportUnitOfWork(AirportContext context)
 {
     this.context = context;
     Airplane     = new RepositoryAirplane(context);
     Passanger    = new RepositoryPassanger(context);
     Reservation  = new RepositoryReservation(context);
     Seat         = new RepositorySeat(context);
     Flight       = new RepositoryFlight(context);
     User         = new RepositoryUser(context);
 }
示例#28
0
 public ManagerLanguage(IHttpContextAccessor httpContextAccessor,
                        ILoggerFactory logger,
                        RepositoryRole repositoryRole,
                        RepositoryUser repositoryUser,
                        ManagerUser managerUser,
                        IMapper mapper,
                        IRepositoryLanguage repositoryLanguage) : base(httpContextAccessor, logger, repositoryRole, repositoryUser, managerUser, mapper)
 {
     _repositoryLanguage = repositoryLanguage;
 }
 public void SetStatus(List <int> IDs)
 {
     foreach (var item in IDs)
     {
         var data = new RepositoryUser().Get(item);
         data.Status           = !data.Status;
         data.DateModification = DateTime.UtcNow;
         new RepositoryUser().Update(data);
     }
 }
        public bool Validate(string token, string URL, AuditAction action)
        {
            try
            {
                var  dataUsuario = new RepositoryUser().GetToken(token);
                var  dataPermiso = GetAll(dataUsuario.ProfileID);
                var  dataModulo  = new RepositoryModule().GetURL(URL);
                bool AllowAccess = false;

                switch (action)
                {
                case AuditAction.Access:
                    AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Access;
                    break;

                case AuditAction.Read:
                    AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Read;
                    break;

                case AuditAction.Add:
                    AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Add;
                    break;

                case AuditAction.Update:
                    AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Update;
                    break;

                case AuditAction.Delete:
                    AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Delete;
                    break;

                case AuditAction.Export:
                    AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Export;
                    break;

                default:
                    AllowAccess = false;
                    break;
                }

                if (AllowAccess)
                {
                    new BusinessAudit().Insert(new ModelViewAudit()
                    {
                        ModuleID = dataModulo.ModuleID, UserID = dataUsuario.UserID, Action = action.ToString()
                    });
                }

                return(AllowAccess);
            }
            catch
            {
                return(true);
            }
        }