Exemple #1
0
        public async Task <RegisterViewModel> Register(RegisterViewModel model)
        {
            var user   = mapper.Map <AppUser> (model);
            var result = await this.repositories.Users.Register(user, user.Password);

            var errors = mapper.Map <List <Message> > (result.Errors.Select(x => new Message(x.Code, x.Description)).ToList());

            if (!result.Succeeded)
            {
                model.AddErrors(errors);
            }
            return(model);
        }
Exemple #2
0
        public async Task <RegisterViewModel> register([FromBody] RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();
                var temp = errors.SelectMany(x => x).ToList();
                model.AddErrors(temp.Select(x => new Message(x.ErrorMessage)).ToList());
                return(model);
            }
            var result = await this.authService.Register(model);

            if (result.Errors.Count == 0)
            {
                await this.profileService.CreateProfile(model.emailGroup.FirstOrDefault().Value);

                var callbackUrl = await this.authService.GetConfirmationUrl(model, Url.Link("ConfirmEmailRoute", ""));

                await this.emailSender.SendConfirmationEmailAsync(model.emailGroup.FirstOrDefault().Value, "Please confirm your email", callbackUrl);
            }
            return(result);
        }