Пример #1
0
        public async Task <IActionResult> Create([FromForm] String email, [FromForm] String username)
        {
            var result = String.Empty;
            var error  = String.Empty;

            try
            {
                var id      = _profiles.Create();
                var userObj = new User
                {
                    Email     = email,
                    Username  = username,
                    ProfileId = id.VerificationProfileId
                };

                _dbContext.ExtUsers.Add(userObj);
                await _dbContext.SaveChangesAsync();

                result = "success";
            }
            catch (Exception ex)
            {
                result = "success";
                error  = ex.Message;
            }

            return(RedirectToAction(nameof(Index), new { result, error }));
        }
Пример #2
0
        public void TestGetProfileByCompanyCvr()
        {
            ProfileService service = new ProfileService();
            CompanyProfile profile = new CompanyProfile()
            {
                CompanyCvr  = 12345678,
                ProfileText = "This is the profile"
            };

            service.Create(profile);
            CompanyProfile profile2 = new CompanyProfile()
            {
                CompanyCvr  = 23456789,
                ProfileText = "This is the second profile"
            };

            service.Create(profile2);

            Assert.AreEqual(service.Get(profile2.CompanyCvr).CompanyCvr, 23456789);
        }
Пример #3
0
        public void TestCreateProfile()
        {
            ProfileService service = new ProfileService();
            CompanyProfile profile = new CompanyProfile()
            {
                CompanyCvr  = 12345678,
                ProfileText = "This is the profile"
            };

            service.Create(profile);
            CompanyProfile profile2 = new CompanyProfile()
            {
                CompanyCvr  = 23456789,
                ProfileText = "This is the second profile"
            };

            service.Create(profile2);

            Assert.AreEqual(profile.CompanyCvr, 12345678);
        }
Пример #4
0
 public ActionResult <Profile> Post([FromBody] Profile newProfile)
 {
     try
     {
         var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         newProfile.UserId = userId;
         return(Ok(_ps.Create(newProfile)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Пример #5
0
        public void TestDeleteProfile()
        {
            ProfileService service = new ProfileService();
            CompanyProfile profile = new CompanyProfile()
            {
                CompanyCvr  = 12345678,
                ProfileText = "This is the profile"
            };

            service.Create(profile);
            CompanyProfile profile2 = new CompanyProfile()
            {
                CompanyCvr  = 23456789,
                ProfileText = "This is the second profile"
            };

            service.Create(profile2);
            service.Delete(profile2.CompanyCvr);

            Assert.IsFalse(service.GetAll().Exists(x => x.CompanyCvr == profile2.CompanyCvr));
            Assert.AreEqual(service.GetAll().Count, 1);
        }
Пример #6
0
        public async Task <ActionResult> Create([FromBody] Profile profile)
        {
            string password = profile.Email;

            if (await _profileService.Create(profile, password))
            {
                return(Ok());
            }
            else
            {
                return(NotFound());
            }
        }
Пример #7
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new MyIdentityServiceUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    var newProfile = new Profile {
                        AppUserId  = user.Email,
                        IdentityId = user.Id,
                        Name       = user.Email,
                        Friends    = new List <string>()
                        {
                        }
                    };

                    _profileService.Create(newProfile);


                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Пример #8
0
 public ActionResult <Profile> Create([FromBody] Profile Profile)
 {
     try
     {
         string nameIdentifier = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         if (nameIdentifier != null)
         {
             Profile.Email = nameIdentifier;
             return(Ok(_profileService.Create(Profile)));
         }
         else
         {
             throw new UnauthorizedAccessException("Unauthorized");
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Пример #9
0
        public async Task <IActionResult> Create([Bind("ProfileId,Nume,MailAdress,Description,Password,NrLikesT,NrDislikesT,NrSubscribers,SubscriptionId")] Profile profile)
        {
            var user = new IdentityUser {
                UserName = profile.MailAdress, Email = profile.MailAdress
            };

            var result = await userManager.CreateAsync(user, profile.Password);

            var userId = user.Id;

            profile.ProfileId = user.Id;

            if (ModelState.IsValid)
            {
                await userManager.AddToRoleAsync(user, "User");

                profileService.Create(profile);
                return(RedirectToAction(nameof(Home)));
            }

            return(View());
        }
Пример #10
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = Input.Email, Email = Input.Email, EmailConfirmed = true
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                Profile profile = new Profile();
                var     userId  = user.Id;
                profile.ProfileId      = user.Id;
                profile.Nume           = Input.Nume;
                profile.MailAdress     = Input.Email;
                profile.Description    = Input.Description;
                profile.Password       = Input.Password;
                profile.NrLikesT       = 0;
                profile.NrDislikesT    = 0;
                profile.NrSubscribers  = 0;
                profile.SubscriptionId = 1;

                await _userManager.AddToRoleAsync(user, "User");

                profileService.Create(profile);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    //var callbackUrl = Url.Page(
                    //    "/Account/ConfirmEmail",
                    //    pageHandler: null,
                    //    values: new { area = "Identity", userId = user.Id, code = code },
                    //    protocol: Request.Scheme);

                    //await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                    //    $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Пример #11
0
        public ActionResult <UserProfile> Create(UserProfile profile)
        {
            _profileService.Create(profile);

            return(CreatedAtRoute("GetProfile", new { id = profile.Id.ToString() }, profile));
        }
Пример #12
0
        public ActionResult Register(RegisterModel register)
        {
            if (ModelState.IsValid)
            {
                register.Subject   = "";
                register.Serial    = "";
                register.ValidFrom = "10/01/2018";
                register.ValidTo   = "10/01/2020";
                var profile = new Profile
                {
                    CompanyName          = register.CompanyName,
                    Email                = register.Email,
                    Phone                = register.Phone,
                    Fax                  = null,
                    CompanyCode          = register.CompanyCode,
                    Address              = register.Address,
                    Province             = register.Province,
                    StartOfFinancialYear = null,
                    TaxAgencyCode        = register.TaxAgencyCode,
                    TaxAgencyName        = register.TaxAgencyName,
                    Issuer               = register.Issuer,
                    Subject              = register.Subject,
                    Serial               = register.Serial,
                    ValidFrom            = DateTime.Parse(register.ValidFrom,
                                                          System.Globalization.CultureInfo.
                                                          GetCultureInfo("vi-VN").
                                                          DateTimeFormat),
                    ValidTo = DateTime.Parse(register.ValidTo,
                                             System.Globalization.CultureInfo.
                                             GetCultureInfo("vi-VN").
                                             DateTimeFormat),
                };

                var password = register.NewPassword;
                var salt     = EntityUtils.GenerateRandomBytes(Constants.PasswordSaltLength);
                var pwdHash  = EntityUtils.GetInputPasswordHash(password, salt);
                var accounts = new Account()
                {
                    ProfileId        = profile.Id,
                    CompanyCode      = register.CompanyCode,
                    PasswordHash     = pwdHash,
                    PasswordSalt     = salt,
                    CompanyName      = register.CompanyName,
                    Representative   = register.Representative,
                    Address          = register.Address,
                    Phone            = register.Phone,
                    AccountType      = null,
                    BankAccount      = register.BankAccount,
                    BankName         = null,
                    ActivationTime   = DateTime.Now,
                    DateExpired      = DateTime.Now,
                    DeactivationTime = DateTime.Now,
                    // LastLoginDate = DateTime.Now
                };

                using (var scope = new TransactionScope())
                {
                    _pro.Create(profile);

                    accounts.ProfileId = profile.Id;
                    _acc.Create(accounts);
                    scope.Complete();
                }
            }
            else
            {
                return(View());
            }

            return(null);
        }