예제 #1
0
        public async Task <(bool Status, string Message)> CreateUser(UserModel model)
        {
            var user = new User().Assign(model);

            user.UserName = model.Email;
            // user.UserId = model.Id;

            var result = await _userManager.CreateAsync(user, model.Password);


            if (result.Succeeded)
            {
                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.NameIdentifier, user.Id),

                    new Claim(ClaimTypes.Name, user.FirstName ?? ""),
                    new Claim(ClaimTypes.Email, user.Email ?? ""),
                    new Claim(ClaimTypes.GivenName, user.FirstName ?? ""),
                    new Claim(ClaimTypes.MobilePhone, user.PhoneNumber),
                    new Claim(ClaimTypes.Surname, model.LastName ?? ""),
                    new Claim(ClaimTypes.Role, model.UserType)
                };
                var claimResult = await _userManager.AddClaimsAsync(user, claims);

                if (claimResult.Succeeded)
                {
                    _notification.SendMail(new MailModel
                    {
                        Content =
                            $"Dear {model.FullName} Your account has been created successfully as a {model.UserType}<br />" +
                            $" Your Login Details: <br/> Username : {model.Email} <br/> Password: {model.Password}<br /> click the link below" +
                            $"to login <a href='{HtmlEncoder.Default.Encode(Constants.AGROEX_URL + "/Account/Login")}'>clicking here</a> ",

                        DateCreated = DateTime.Now,
                        Subject     = "Account Creation In AgroEX Commodities",
                        To          = model.Email
                    });
                    return(true, "The user has been created with the right claims");
                }
            }
            return(false, "Unable to create the user, try again later");
        }
예제 #2
0
        public async Task <(bool Status, string Message)> RegisterUser(UserModel model)
        {
            var user = new User().Assign(model);

            user.UserName = model.Email;
            user.UserType = model.RegistrationType;
            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, user.FirstName ?? ""),
                    new Claim(ClaimTypes.Email, user.UserName ?? ""),
                    new Claim(ClaimTypes.MobilePhone, user.PhoneNumber),
                    new Claim(ClaimTypes.Surname, model.LastName ?? ""),
                    new Claim(ClaimTypes.Role, model.RegistrationType)
                };
                var claimResult = await _userManager.AddClaimsAsync(user, claims);

                if (claimResult.Succeeded)
                {
                    var code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, Constants.DefaultPhone);


                    _notification.SendMail(new MailModel
                    {
                        To      = model.Email,
                        Subject = "AGRO Commodities Exchange",
                        Content = $"Dear {model.FirstName}Your account has been created successfully as a {model.RegistrationType}<br />" +
                                  $" Your Login Details: <br/> Username : {model.Email} <br/> <br /> click the link below" +
                                  $"to login <a href='{HtmlEncoder.Default.Encode(Constants.AGROX_URl + "/Account/Login")}'>CLick here</a> or" +
                                  $"<a href='{HtmlEncoder.Default.Encode(code)}'>CLick here</a> ",
                    });
                    return(true, "The user has been created with the right claims");
                }
            }
            return(false, "Unable to create user");
        }