public async Task <ActionResult <SignupInfo> > Post(SignupInfo newSignup)
        {
            _signups.Add(newSignup);

            _logger.LogInformation("Added new signup with Id {id}", newSignup.Id);

            return(newSignup);
        }
        public HttpResponseMessage Post([FromBody] SignupInfo info)
        {
            JinderDBConnection dbContext = new JinderDBConnection();
            var usersTable = dbContext.JinderUsers;

            JinderUser jinderUser = (from user in usersTable
                                     where user.Username == info.Username
                                     select user).FirstOrDefault <JinderUser>();

            HttpResponseMessage message = new HttpResponseMessage();

            if (jinderUser != null)
            {
                message.StatusCode = HttpStatusCode.Conflict;
                message.Content    = new StringContent("Username: "******" is already registered.");

                return(message);
            }

            JinderUser newUser = new JinderUser();

            newUser.Username       = info.Username;
            newUser.Password       = info.Password;
            newUser.FullName       = info.FullName;
            newUser.DateOfBirth    = info.DateOfBirth;
            newUser.ProfilePicture = info.ProfilePicture;
            newUser.Gender         = info.Gender;
            newUser.Address        = info.Address;
            newUser.UserType       = info.UserType;

            usersTable.Add(newUser);
            dbContext.SaveChanges();

            if (info.UserType == "seeker")
            {
                SeekerProfile newSeekerProfile = new SeekerProfile();
                newSeekerProfile.JinderUserId  = newUser.JinderUserId;
                newSeekerProfile.Education     = info.Education;
                newSeekerProfile.Experience    = info.Experience;
                newSeekerProfile.Skills        = info.Skills;
                newSeekerProfile.Certification = info.Certification;

                var seekersTable = dbContext.SeekerProfiles;
                seekersTable.Add(newSeekerProfile);

                dbContext.SaveChanges();
            }

            message.StatusCode = HttpStatusCode.Created;
            return(message);
        }
Exemple #3
0
        public async Task <IActionResult> Signup(SignupInfo model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var account = dataRepository.GetAccount(model.MobileNumber);

                    if (account != null)
                    {
                        throw new InvalidOperationException("Already an account exist with the same phone number.");
                    }

                    account = new Account
                    {
                        IsActive  = true,
                        LastLogin = DateTime.Now,
                        Mobile    = model.MobileNumber,
                        Name      = model.Name,
                        Pin       = model.Pin,
                        Tokens    = 0
                    };
                    dataRepository.CreateAccount(account);
                    var claims = new List <Claim>
                    {
                        new Claim(ClaimTypes.Name, model.MobileNumber),
                        new Claim(ClaimTypes.MobilePhone, model.MobileNumber),
                        new Claim(ClaimTypes.Sid, $"{account.Id}")
                    };

                    var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
                                                  new ClaimsPrincipal(claimsIdentity),
                                                  new AuthenticationProperties());

                    return(RedirectToAction(nameof(SessionController.Index), "Session"));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError(string.Empty, e.Message);
                    return(View(model));
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Unable to signup");
                return(View(model));
            }
        }
        public async Task <ActionResult> Signup(SignupInfo account, String returnUrl)
        {
            if (ModelState.IsValid)
            {
                User user = new User {
                    UserName = account.Name, Email = account.Email
                };
                IdentityResult result = await UserManager.CreateAsync(user, account.Password);

                if (result.Succeeded)
                {
                    User createdUser = await UserManager.FindAsync(account.Name, account.Password);

                    // assign the user to customer role
                    IdentityResult roleResult = await UserManager.AddToRoleAsync(createdUser.Id, "Customer");

                    if (!roleResult.Succeeded)
                    {
                        AddErrorMessage(roleResult);
                    }
                    else
                    {
                        ClaimsIdentity identity = await UserManager.CreateIdentityAsync(createdUser,
                                                                                        DefaultAuthenticationTypes.ApplicationCookie);

                        AuthManager.SignOut();
                        AuthManager.SignIn(new AuthenticationProperties {
                            IsPersistent = true
                        }, identity);

                        if (String.IsNullOrEmpty(returnUrl))
                        {
                            return(RedirectToAction("List", "Book"));
                        }
                        else
                        {
                            // if a return url exist, user will be sent to the page
                            return(Redirect(returnUrl));
                        }
                    }
                }
                else
                {
                    AddErrorMessage(result);
                }
            }

            return(View(account));
        }
        public HttpResponseMessage Post([FromBody] SignupInfo info)
        {
            JinderDBEntities dbContext = new JinderDBEntities();
            var usersTable             = dbContext.JinderUsers;

            JinderUser jinderUser = (from user in usersTable
                                     where user.Username == info.Username
                                     select user).FirstOrDefault <JinderUser>();

            HttpResponseMessage message = new HttpResponseMessage();

            if (jinderUser != null)
            {
                message.StatusCode = HttpStatusCode.Conflict;
                message.Content    = new StringContent("Username: "******" is already registered.");

                return(message);
            }

            JinderUser newUser = new JinderUser();

            newUser.Username    = info.Username;
            newUser.Password    = info.Password;
            newUser.FullName    = info.Fullname;
            newUser.DateOfBirth = info.DateOfBirth;
            newUser.Gender      = info.Gender;
            newUser.Address     = info.Address;
            newUser.UserType    = info.UserType;

            usersTable.Add(newUser);
            dbContext.SaveChanges();


            message.StatusCode = HttpStatusCode.Created;
            return(message);
        }
Exemple #6
0
        public IActionResult Signup([FromBody] SignupInfo signupInfo)
        {
            var account = Ledger.Accounts.SingleOrDefault(a => a.Username == signupInfo.Username.ToLower());

            if (account != null)
            {
                return(BadRequest("Username is already registered."));
            }

            CreatePasswordHash(signupInfo.Password, out byte[] passwordHash, out byte[] passwordSalt);

            account = new Account
            {
                Username     = signupInfo.Username.ToLower(),
                FirstName    = signupInfo.FirstName,
                LastName     = signupInfo.LastName,
                PasswordHash = passwordHash,
                PasswordSalt = passwordSalt
            };

            Ledger.Accounts.Add(account);

            return(StatusCode(StatusCodes.Status201Created));
        }
Exemple #7
0
        public ActionResult Submit(StartPage currentPage, SignupInfo Signup)
        {
            //Send emails to sender and receiver

            return(PartialView("SubmitSuccess"));
        }