コード例 #1
0
        public static Userprofile GetUserProfile(string email)
        {
            AppUser     appUser                  = null;
            Userprofile userprofile              = null;
            var         userProfileApiTokenUrl   = ConfigurationManager.AppSettings["UserProfileApiTokenUrl"];
            var         userProfileApiProfileUrl = ConfigurationManager.AppSettings["UserProfileApiProfileUrl"];
            var         userProfileApiUserName   = ConfigurationManager.AppSettings["UserProfileApiUserName"];
            var         userProfileApiPassword   = ConfigurationManager.AppSettings["UserProfileApiPassword"];

            var token = GetUserProfileAccessToken(userProfileApiTokenUrl, userProfileApiUserName, userProfileApiPassword);

            var profileUrl = userProfileApiProfileUrl + email + '/';

            if (token != null)
            {
                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token);
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    appUser = JsonConvert.DeserializeObject <AppUser>(client.GetStringAsync(profileUrl).Result);

                    if (appUser != null)
                    {
                        userprofile = appUser.UserProfile;
                    }
                }
            }

            return(userprofile);
        }
コード例 #2
0
        public async Task <bool> Add(Userprofile item)
        {
            try
            {
                var           obj     = JsonConvert.SerializeObject(item);
                StringContent content = new StringContent(obj);
                var           result  = await client.ClientContext.PostAsync("/Api/UserProfile", content);

                if (result.IsSuccessStatusCode)
                {
                    var newitem = JsonConvert.DeserializeObject <Userprofile>(result.Content.ReadAsStringAsync().Result);
                    this.Source.Add(newitem);
                    return(true);
                }
                else
                {
                    throw new SystemException("Data Tidak Tersimpan");
                }
            }
            catch (Exception ex)
            {
                ResourcesBase.ShowMessageError(ex.Message);
                return(false);
            }
        }
コード例 #3
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            var user = new ApplicationUser {
                UserName = model.UserName, Email = model.Email
            };

            if (model.Password == model.ConfirmPassword)
            {
                IdentityResult result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var newUserprofile = new Userprofile {
                        Name = model.UserName, Gender = "", Age = 0, Bio = "", Photo = "", Location = "", ApplicationUserId = user.Id
                    };
                    Userprofile.CreateUserProfile(newUserprofile);
                    return(RedirectToAction("Login"));
                }
                else
                {
                    ViewBag.ErrorMessage = "Registration Unsuccessful. A password must include at least six characters, a capital letter, a number, and a special character. If your password meets these requirements, try registering with a different username.";
                    return(View());
                }
            }
            else
            {
                ViewBag.ErrorMessage = "Your passwords didn't match! Try again!";
                return(View());
            }
        }
コード例 #4
0
        public async Task SendAsync(Userprofile profile, string title, string body)
        {
            try
            {
                using (var message = new MailMessage())
                {
                    message.To.Add(new MailAddress(profile.Email));
                    message.SubjectEncoding = Encoding.UTF8;
                    message.Subject         = title;

                    message.BodyEncoding = Encoding.UTF8;
                    message.Body         = body;

                    SendMail.Post(message);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
                if (Logger.DebugEnabled)
                {
                    Logger.Debug(e.StackTrace);
                }
            }
        }
コード例 #5
0
ファイル: Authentication.cs プロジェクト: ezyuzin/safevault
        private bool AuthenticateWithOneTimePassword(Userprofile profile, string password)
        {
            if (password.Length > 8 || password != Regex.Replace(password, @"[^0-9]", ""))
            {
                return(false);
            }

            bool authenticated = false;
            var  secret        = Base32.Decode(profile.SecretKey);

            for (int i = 0; !authenticated && i < 3; i++)
            {
                var passw = OneTimePassword.Get(secret, i);
                authenticated = (passw == password);

                if (!authenticated && i != -i)
                {
                    passw         = OneTimePassword.Get(secret, -i);
                    authenticated = (passw == password);
                }
            }

            if (authenticated)
            {
                TokenList.UseToken($"otp/{profile.Username}/{password}");
            }

            return(authenticated);
        }
コード例 #6
0
 public void Post([FromBody] Userprofile userprofile)
 {
     userprofile.UserprofileId = _currentId;
     _currentId++;
     _db.Userprofiles.Add(userprofile);
     _db.SaveChanges();
 }
コード例 #7
0
        public async Task <ActionResult> Prev()
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            var allUserprofiles   = Userprofile.GetAllUserprofilesPrev();
            var otherUserprofiles = allUserprofiles.Where(x => x.ApplicationUserId != currentUser.Id);

            return(View("Index", otherUserprofiles));
        }
コード例 #8
0
 public async Task <IActionResult> Post([FromBody] Userprofile t)
 {
     try
     {
         return(Ok(await context.Post(t)));
     }
     catch (Exception ex)
     {
         return(BadRequest(new ErrorMessage(ex.Message)));
     }
 }
コード例 #9
0
        public ActionResult ProfileView()
        {
            AuthenticationClient authentication = new AuthenticationClient();
            ExpenseClient        _exp           = new ExpenseClient();
            var profile = new Userprofile();

            profile.UserProfile = authentication.GetUserProfile(Convert.ToInt32(Session["UserId"].ToString())).ToList();
            profile.Country     = authentication.CountrtyList().ToList();
            profile.Friends     = _exp.GetFriendsList(Convert.ToInt32(Session["UserId"].ToString())).ToList();
            return(View(profile));
        }
コード例 #10
0
 public async Task <IActionResult> Put(int id, [FromBody] Userprofile value)
 {
     try
     {
         return(Ok(await context.Put(id, value)));
     }
     catch (Exception ex)
     {
         return(BadRequest(new ErrorMessage(ex.Message)));
     }
 }
コード例 #11
0
        public async Task <ActionResult> Details(int id)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            var myCircles = Circle.GetAllCircles().Where(x => x.ApplicationUserId == currentUser.Id);

            ViewBag.CircleId = new SelectList(myCircles, "CircleId", "Name");
            var thisUserprofile = Userprofile.GetThisUserprofile(id);

            return(View(thisUserprofile));
        }
コード例 #12
0
 private void ChangeRoleViews(Userprofile selected)
 {
     if (selected != null && selected.User != null)
     {
         RoleSource.Clear();
         foreach (var item in selected.User.Userrole)
         {
             RoleSource.Add(item.Role);
         }
         RolesView.Refresh();
         Roles.Refresh();
     }
 }
コード例 #13
0
        public void Userprofile010Test()
        {
            var location = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            Userprofile userprofile = new Userprofile();

            userprofile.Path = $"{location}/data/client/test-user";
            userprofile.LoadProfile();

            Assert.AreEqual("*****@*****.**", userprofile.GetValue("email"));
            Assert.AreEqual("12345678", userprofile.GetValue("secret-key"));
            Assert.AreEqual("md5:E807F1FCF82D132F9BB018CA6738A19F", userprofile.GetValue("password"));
        }
コード例 #14
0
        internal async Task <bool> RemoveRole(Userprofile selectedItem, Roles roleSelected)
        {
            string url    = string.Format("RemoveRole/{0}/roleid?roleid={1}", selectedItem.User.Id, roleSelected.Id);;
            var    result = await client.ClientContext.DeleteAsync(url);

            if (result.IsSuccessStatusCode)
            {
                return(JsonConvert.DeserializeObject <bool>(result.Content.ReadAsStringAsync().Result));
            }
            else
            {
                return(false);
            }
        }
コード例 #15
0
        public async Task <ActionResult> Edit()
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            var myUserprofile = Userprofile.GetAllUserprofiles().FirstOrDefault(x => x.ApplicationUserId == currentUser.Id);

            if (myUserprofile.ApplicationUserId == currentUser.Id)
            {
                return(View(myUserprofile));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
コード例 #16
0
        public async Task <bool> Put(int id, Userprofile value)
        {
            try
            {
                var profile = db.Userprofile.Where(x => x.Id == id).FirstOrDefault();
                if (profile != null)
                {
                    db.Entry(profile).CurrentValues.SetValues(value);
                    await db.SaveChangesAsync();

                    return(true);
                }
                return(false);
            }
            catch
            {
                throw new SystemException(MessageCollection.Message(MessageType.UpdateFaild));
            }
        }
コード例 #17
0
        internal async Task <bool> Update(Userprofile item)
        {
            var res = await client.PutAsync <bool>("", item.Id, item);

            if (res)
            {
                var userProfile = Source.Where(O => O.Id == item.Id).FirstOrDefault();
                if (userProfile != null)
                {
                    item.FirstName = userProfile.FirstName;
                    item.LastName  = userProfile.LastName;
                    item.Address   = userProfile.Address;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #18
0
        private async void GetProfile()
        {
            Userprofile result = await MainVM.UserProfileCollections.GetProfile();

            if (result != null)
            {
                if (result == null)
                {
                    this.IsNew = true;
                }
                else
                {
                    this.Id        = result.Id;
                    this.FirstName = result.FirstName;
                    this.LastName  = result.LastName;
                    this.UserId    = result.UserId;
                    this.Address   = result.Address;
                    this.Photo     = result.Photo;
                }
            }
        }
コード例 #19
0
 public Task <bool> Post(Userprofile t)
 {
     return(Task.FromResult(false));
 }
コード例 #20
0
 public Userprofile AddUserprofile(Userprofile userprofile)
 {
     return(_UserprofileRepository.AddUserprofile(userprofile));
 }
コード例 #21
0
 public IActionResult Edit(Userprofile userprofile)
 {
     Userprofile.EditUserprofile(userprofile.UserprofileId, userprofile);
     return(RedirectToAction("Index"));
 }
コード例 #22
0
 public void Post([FromBody] Userprofile userprofile)
 {
     _db.Userprofiles.Add(userprofile);
     _db.SaveChanges();
 }
コード例 #23
0
        internal async Task <Roles> AddNewUserRole(Userprofile selectedItem, Roles role)
        {
            string url = string.Format("AddNewRole/{0}", selectedItem.User.Id);

            return(await client.PostAsync <Roles>(url, role));
        }
コード例 #24
0
 public Userprofile UpdateUserprofile(int userprofileId, Userprofile userprofile)
 {
     return(_UserprofileRepository.UpdateUserprofile(userprofileId, userprofile));
 }
コード例 #25
0
        public void PurchaseOrderRequestService_AddValidProductUserRequest_ShouldReturnTrackingMembership()
        {
            using (TransactionScope transactionScope = new TransactionScope())
            {
                // Set up and add a book and membership
                var productBook = new Data.Models.Product.Product
                {
                    Name = "TestBook1",
                    ProductMembershipValue = 0,
                    ProductCategory        = RefProductCategory.Book,
                    ProductForm            = RefProductForm.Physical,
                    UnitCost = 10.99M,
                    Weight   = 1.00M
                };

                var productInput1 = ProductService.AddProduct(productBook);

                var productMem = new Data.Models.Product.Product
                {
                    Name = "TestMembership3",
                    ProductMembershipValue = 90, // 90 days
                    ProductCategory        = RefProductCategory.Video,
                    ProductForm            = RefProductForm.Membership,
                    UnitCost = 30.00M
                };

                var productInput2 = ProductService.AddProduct(productMem);

                #region maybe use later
                //var addBill = new AddressBilling
                //{
                //    Street1 = "1000 Test Dr.",
                //    Street2 = "",
                //    City = "Test1City",
                //    State = RefState.AL,
                //    Zip = 01234
                //};

                //var addShip = new AddressShipping
                //{
                //    Street1 = "1000 Test Dr.",
                //    Street2 = "",
                //    City = "Test1City",
                //    State = RefState.AL,
                //    Zip = 01234
                //};

                #endregion

                // Set up and add a user
                var user = new Userprofile
                {
                    FirstName       = "testF",
                    LastName        = "testL",
                    Email           = "*****@*****.**",
                    UserMemberships = new List <UserMembership>(),
                    PurchaseOrders  = new List <Data.Models.PurchaseOrder.PurchaseOrder>()
                };

                var userprofileInput = UserprofileService.AddUserprofile(user);

                // Setup DTO orderRequest, 1 video membership and 2 books
                var orderReq = new OrderRequest
                {
                    UserprofileId = userprofileInput.Id,
                    ProductIds    = new Dictionary <Data.Models.Product.Product, int>
                    {
                        { productInput1, 2 },
                        { productInput2, 1 }
                    }
                };

                //Act
                var result = PurchaseOrderRequestService.AddPurchaseOrderRequest(orderReq);

                //Assert
                result.Success.Should().BeTrue();

                var testUser = UserprofileService.GetUserprofile(orderReq.UserprofileId);

                // check business reqs on shipment
                result.PurchaseOrder.PurchaseOrderShipments.Where(x => x.PurchaseOrderId == result.PurchaseOrder.Id).Should().NotBeEmpty();
                result.PurchaseOrder.PurchaseOrderShipments.FirstOrDefault(x => x.PurchaseOrderId == result.PurchaseOrder.Id)?.TrackingNumber.Should().HaveLength(32);

                // check business reqs on membership
                result.PurchaseOrder.Userprofile.UserMemberships.ToList().Should().NotBeEmpty();
                result.PurchaseOrder.Userprofile.UserMemberships.ToList().FirstOrDefault()?.MembershipRemaining.Should().Be(90);
            }
        }
コード例 #26
0
 public void Put(int id, [FromBody] Userprofile userprofile)
 {
     userprofile.UserprofileId    = id;
     _db.Entry(userprofile).State = EntityState.Modified;
     _db.SaveChanges();
 }
コード例 #27
0
 public void AddUser(Userprofile userprofile)
 {
     this.dbContext.Userprofiles.Add(userprofile);
     this.dbContext.SaveChanges();
 }
コード例 #28
0
 public void AddUser(Userprofile userprofile)
 {
     this.repository.AddUser(userprofile);
 }