// Redirects the User to the Login Screen
559348
func (self *OAuth2Mixin) AuthorizeRedirect(w http.ResponseWriter, r *http.Request, scope string) {
	state := strconv.FormatInt(stateGenerator.Int63(), 10)
	url := self.Client.AuthorizeRedirect(scope, state)
	http.Redirect(w, r, url, http.StatusSeeOther)
}
1354998
func (c *UserController) PostLogin() mvc.Result {
	var (
		username = c.Ctx.FormValue("username")
		password = c.Ctx.FormValue("password")
	)

	u, found := c.Service.GetByUsernameAndPassword(username, password)

	if !found {
		return mvc.Response{
			Path: "/user/register",
		}
	}

	c.Session.Set(userIDKey, u.ID)

	return mvc.Response{
		Path: "/user/me",
	}
}
103592
func (c *Context) Redirect(code int, location string) error {
	if (code < 300 || code > 308) && code != 201 {
		return fmt.Errorf("Cannot redirect with status code %d", code)
	}
	http.Redirect(c.Writer, c.Request, location, code)
	return nil
}
68325
func (c *Context) Redirect(url string, code int) error {
	if code < http.StatusMultipleChoices || code > http.StatusTemporaryRedirect {
		return errors.New("invalid redirect code")
	}
	http.Redirect(c.response, c.request, url, code)
	return nil
}
829292
func (s *Session) Login(ctx context.Context, creds apitypes.LoginCredential) error {
	if !creds.Valid() {
		return &apitypes.Error{
			Type: apitypes.BadRequestError,
			Err:  []string{"invalid login credentials provided"},
		}
	}

	salt, loginToken, err := s.engine.client.Tokens.PostLogin(ctx, creds)
	if err != nil {
		return err
	}

	mechanism := loginToken.Body.Mechanism
	var authToken *envelope.Token
	switch mechanism {
	case primitive.HMACAuth:
		authToken, err = s.attemptEdDSAUpgrade(ctx, loginToken, salt, creds)
	case primitive.EdDSAAuth:
		authToken, err = s.attemptEdDSALogin(ctx, loginToken, salt, creds)
	default:
		err = &apitypes.Error{
			Type: apitypes.InternalServerError,
			Err:  []string{fmt.Sprintf("unrecognized auth mechanism: %s", mechanism)},
		}
	}
	if err != nil {
		return err
	}

	token := []byte(authToken.Body.Token)
	self, err := s.engine.client.Self.Get(ctx, authToken.Body.Token)
	if err != nil {
		return err
	}

	s.engine.db.Set(self.Identity)
	if self.Type == apitypes.UserSession {
		s.engine.db.Set(self.Auth)
	}

	return s.engine.session.Set(self.Type, self.Identity, self.Auth, creds.Passphrase(), token)
}
386286
func (c *Client) Login(username, password string) error {
	if state := c.State(); state == imap.AuthenticatedState || state == imap.SelectedState {
		return ErrAlreadyLoggedIn
	}

	c.locker.Lock()
	loginDisabled := c.caps != nil && c.caps["LOGINDISABLED"]
	c.locker.Unlock()
	if loginDisabled {
		return ErrLoginDisabled
	}

	cmd := &commands.Login{
		Username: username,
		Password: password,
	}

	status, err := c.execute(cmd, nil)
	if err != nil {
		return err
	}
	if err = status.Err(); err != nil {
		return err
	}

	c.locker.Lock()
	c.state = imap.AuthenticatedState
	c.caps = nil // Capabilities change when user is logged in
	c.locker.Unlock()

	if status.Code == "CAPABILITY" {
		c.gotStatusCaps(status.Arguments)
	}
	return nil
}
1052533
func (user *User) OauthRedirectURL() string {
	providerID := user.ctx.OAuthProvider().internalID()
	if providerID == user.ctx.ServiceName {
		return fmt.Sprintf("%s/auth/%s", Config.BaseURL, user.ctx.ServiceName)
	}

	return fmt.Sprintf("%s/auth/%s/%s", Config.BaseURL, user.ctx.ServiceName, providerID)
}
715773
func (u *UserService) Login(name, passw string) (*loginResponse, error) {

	derived := pbkdf2.Key([]byte(passw), []byte(reverse(passw)), 1000, 16, sha1.New)

	reqParams := url.Values{
		"auth": []string{name},
		"pass": []string{fmt.Sprintf("%x", derived)},
	}

	oldHost := u.c.api.Api.BaseUrl.Host
	u.c.api.Api.BaseUrl.Host = strings.Replace(oldHost, "api.oboom.com", "www.oboom.com", 1)

	res := u.c.api.Res("login")
	res.Headers.Set("Content-Type", "application/x-www-form-urlencoded")
	res.Payload = strings.NewReader(reqParams.Encode())
	resp, err := res.FormPost(nil)
	arr, err := processResponse(resp, err)
	if err != nil {
		return nil, err
	}

	u.c.api.Api.BaseUrl.Host = oldHost

	var liResp loginResponse
	if err = decodeInto(&liResp, arr[1]); err != nil {
		return nil, err
	}

	u.session = liResp.Session

	return &liResp, nil
}
1089601
func (c *Client) Login() (string, error) {
	payload := &Request{
		Action: "login",
		Param: &LoginRequest{
			CustomerNumber:  c.customerNumber,
			APIKey:          c.apiKey,
			APIPassword:     c.apiPassword,
			ClientRequestID: "",
		},
	}

	var responseData LoginResponse
	err := c.doRequest(payload, &responseData)
	if err != nil {
		return "", fmt.Errorf("loging error: %v", err)
	}

	return responseData.APISessionID, nil
}
367914
func (c *Client) Login(ctx context.Context) (err error) {
	var req *APIRequest
	var resp *APIResponse

	req, err = c.NewRequest("GET", "api/agents", nil, apiV2)
	if err != nil {
		return
	}
	req.HTTP.SetBasicAuth(c.params.Username, c.params.Password)

	resp, err = c.Do(ctx, req, nil, responseTypeJSON)
	if err == nil {
		c.cookie = resp.HTTP.Header["Set-Cookie"][0]
	}
	return
}
501547
func (c *ctx) Redirect(urlStr string) error {
	if c.code < 300 || c.code > 308 {
		return ErrInvalidRedirectStatusCode
	}

	http.Redirect(c, c.Request(), urlStr, c.code)
	return nil
}
172116
func (h *HTTPBin) RedirectTo(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()

	url := q.Get("url")
	if url == "" {
		http.Error(w, "Missing URL", http.StatusBadRequest)
		return
	}

	var err error
	statusCode := http.StatusFound
	rawStatusCode := q.Get("status_code")
	if rawStatusCode != "" {
		statusCode, err = strconv.Atoi(q.Get("status_code"))
		if err != nil || statusCode < 300 || statusCode > 399 {
			http.Error(w, "Invalid status code", http.StatusBadRequest)
			return
		}
	}

	w.Header().Set("Location", url)
	w.WriteHeader(statusCode)
}
1207988
func (self *OAuth1Mixin) Redirect(w http.ResponseWriter, r *http.Request) {
	if err := self.AuthorizeRedirect(w, r, self.Consumer.AuthorizationURL); err != nil {
		println("Error redirecting to authorization endpoint: " + err.Error())
	}
}
1071153
func (r *redirector) AuthenticationRedirect(w http.ResponseWriter, req *http.Request) error {
	redirectURL, err := buildRedirectURL(r.RedirectURL, r.BaseRequestURL, req.URL)
	if err != nil {
		return nil
	}
	http.Redirect(w, req, redirectURL.String(), http.StatusFound)
	return nil
}
1246752
func (c *UserController) GetMe() mvc.Result {
	if !c.isLoggedIn() {
		// if it's not logged in then redirect user to the login page.
		return mvc.Response{Path: "/user/login"}
	}

	u, found := c.Service.GetByID(c.getCurrentUserID())
	if !found {
		// if the  session exists but for some reason the user doesn't exist in the "database"
		// then logout and re-execute the function, it will redirect the client to the
		// /user/login page.
		c.logout()
		return c.GetMe()
	}

	return mvc.View{
		Name: "user/me.html",
		Data: iris.Map{
			"Title": "Profile of " + u.Username,
			"User":  u,
		},
	}
}
186475
func (m UsersAPIAuthMethod) LoginURL(c context.Context, dest string) (string, error) {
	url, err := user.LoginURL(c, dest)
	if err != nil {
		return "", err
	}
	if !strings.HasPrefix(url, serviceLoginURL) {
		if !info.IsDevAppServer(c) {
			logging.Warningf(c, "Unexpected login URL: %q", url)
		}
		return url, nil
	}
	// Give the user a choice of existing accounts in their session or the option
	// to add an account, even if they are currently signed in to exactly one
	// account.
	return accountChooserURL + url[len(serviceLoginURL):], nil
}
957049
func login(ctx *cli.Context) {
	if len(ctx.Args()) != 0 {
		errExit(ctx, exitHelp, "More arguments than required", true)
	}

	// this check is redundant as ContivClient's Login() function also verifies
	// that the URL is https.  this is just for a better UX.  prompting for username
	// and password and then showing an error immediately is kind of lame.
	if !strings.HasPrefix(baseURL(ctx), "https://") {
		fmt.Println("login requires a https auth_proxy URL")
		errExit(ctx, exitInvalid, "", true)
	}

	username, password := readLoginCredentials(ctx)

	// perform the login
	resp, body, err := getClient(ctx).Login(username, password)
	if err != nil {
		errExit(ctx, exitIO, err.Error(), false)
	}

	// check the status code to see if the login succeeded
	if resp.StatusCode != http.StatusOK {
		fmt.Print("Login failed: ")

		if resp.StatusCode == http.StatusUnauthorized {
			fmt.Println("Bad username or password.")
		} else {
			fmt.Printf("unexpected response code (%d)\n\n", resp.StatusCode)
			os.Stderr.Write(body)
		}

		// exit without any additional output
		errExit(ctx, exitInvalid, "", false)
	}

	fmt.Println("Login succeeded.")

	// for now, we will just write out the raw JSON response as the netctl config file since it
	// contains nothing but the token.  we can extend the config file format in the future.
	writeConfig(ctx, body)
}